A drop-in replacement to any Writer type, which also calculates a hash using the provided hash type.

writehasher

A drop-in replacement to any Writer type, which also calculates a hash using the provided hash type.

Example

package main

import (
	"fmt"
	"hash"
	"hash/crc32"
	"hash/crc64"
	"io"

	"github.com/maard/writehasher"
)

func main() {
	var w io.Writer = io.Discard
	data := "the hash of this data needs to be calculated"

	// Usage with types, which implement hash.Hash, for instance:
	// hasher := NewWriteHasher(w, crc32.NewIEEE())
	// hasher := NewWriteHasher(w, crc64.New(crc64.MakeTable(crc64.ISO)))
	// hasher := NewWriteHasher(w, crc64.New(crc64.MakeTable(crc64.ECMA)))
	// hasher := NewWriteHasher(w, md5.New())
	// hasher := NewWriteHasher(w, sha1.New())
	// hasher := NewWriteHasher(w, sha256.New())
	// hasher := NewWriteHasher(w, sha512.New())

	hasher := NewWriteHasher(w, md5.New())
	io.WriteString(hasher, data)
	fmt.Printf("%x\n", hasher.Sum())

	hasher = NewWriteHasher(w, crc32.NewIEEE())
	io.WriteString(hasher, data)
	fmt.Printf("%x\n", hasher.Sum())

	// Usage with types, which also implement hash.Hash32, for instance:
	hasher = NewWriteHasher32(w, crc32.NewIEEE())
	io.WriteString(hasher, data)
	fmt.Printf("%x\n", hasher.Sum32())

	// Usage with types, which also implement hash.Hash64, for instance:
	hasher = NewWriteHasher64(w, crc64.New(crc64.MakeTable(crc64.ISO)))
	io.WriteString(hasher, data)
	fmt.Printf("%x\n", hasher.Sum64())
}
// prints:
// b9a9aa9d96160f293562ffcfc543bc1d
// 8dfa06fe
// 8dfa06fe
// 7fac11fe2939f29

API

hasher := NewWriteHasher(w io.Writer, h hash.Hash)

hasher := NewWriteHasher32(w io.Writer, h hash.Hash32)

hasher := NewWriteHasher64(w io.Writer, h hash.Hash64)

Creates a class instance.

hasher.Sum()

hasher.Sum32()

hasher.Sum64()

Returns the hash of the data, written to hasher ([]byte, uint32, uint64 respectively)

Similar Resources

Automatic HTTPS for any Go program: fully-managed TLS certificate issuance and renewal

Automatic HTTPS for any Go program: fully-managed TLS certificate issuance and renewal

Easy and Powerful TLS Automation The same library used by the Caddy Web Server Caddy's automagic TLS featuresβ€”now for your own Go programsβ€”in one powe

Jan 8, 2023

Convert any EIP-2335 keystores to scrypt or pbkdf2

eth2-keystore-converter Converts Eth2 EIP-2335 scrypt keystores to pbkdf2 keysto

May 13, 2022

Ransomware: a type of malware that prevents or limits users from accessing their system

Ransomware: a type of malware that prevents or limits users from accessing their system

Ransomware Note 1: This project is purely academic, use at your own risk. I do not encourage in any way the use of this software illegally or to attac

Nov 17, 2021

Berylbit PoW chain using Ethash, EPI-Burn and geth. The chain will be using bot congestion flashbot bundles through nodes

Berylbit PoW chain using Ethash, EPI-Burn and geth. The chain will be using bot congestion flashbot bundles through nodes. Soon, We will work towards

Jun 30, 2022

GUI application for Raspberry PI which allows simultaneous manipulation of infrared and nightvision cameras

IRNC GUI application for Raspberry PI which allows simultaneous manipulation of infrared and nightvision cameras IRNC stands for "InfraRed and Nightvi

Nov 25, 2021

Troon-NFT-Contract is deployed on Flow Blockchain, which is a white-label smart-contract for NFTs with an addition layer of Brand, Schema and Template

Overview Summary of NFTContract NFTContract is a Non Fungible Token (NFT) standard for Flow blockchain. It offers a powerful set while keeping unneces

Jan 4, 2022

🌰 encrypt/decrypt using ssh keys

ssh-vault 🌰 encrypt/decrypt using ssh private keys Documentation https://ssh-vault.com Usage $ ssh-vault -h Example: $ echo "secret" | ssh-vault -u

Dec 30, 2022

A command line Crypto-currency ticker made using golang and WazirX Api

A command line Crypto-currency ticker made using golang and WazirX Api

β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•— β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•”β•β•β•β•β•β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•‘β–‘β–‘β•šβ•β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”

Feb 6, 2022

Frontier Chain is a blockchain application built using Cosmos SDK and Tendermint.

Frontier Chain Frontier Chain is a blockchain application built using Cosmos SDK and Tendermint. Setup Initialize the blockchain with one validator no

Jul 12, 2022
Vso-hash - Golang implementation of the BuildXL paged hash function

vso-hash Golang implementation of the BuildXL paged hash function See https://gi

Jan 3, 2022
Use the HashPassword function to generate a hashed value for the provided password

hasher Use the 'HashPassword' function to generate a hashed value for the provided password. h, err := hasher.HashPassword("password") // h == XohImNo

Nov 1, 2021
An easy-to-use XChaCha20-encryption wrapper for io.ReadWriteCloser (even lossy UDP) using ECDH key exchange algorithm, ED25519 signatures and Blake3+Poly1305 checksums/message-authentication for Go (golang). Also a multiplexer.

Quick start Prepare keys (on both sides): [ -f ~/.ssh/id_ed25519 ] && [ -f ~/.ssh/id_ed25519.pub ] || ssh-keygen -t ed25519 scp ~/.ssh/id_ed25519.pub

Dec 30, 2022
TLS/SSL Tunnel - A modern STunnel replacement written in golang
TLS/SSL Tunnel - A modern STunnel replacement written in golang

go-tunnel - Robust Quic/TLS Tunnel (Stunnel replacement) What is it? A supercharged Stunnel replacement written in golang. is in a sense a proxy enabl

Jan 1, 2023
Go implementation of BLAKE2 (b) cryptographic hash function (optimized for 64-bit platforms).

Go implementation of BLAKE2b collision-resistant cryptographic hash function created by Jean-Philippe Aumasson, Samuel Neves, Zooko Wilcox-O'Hearn, an

Jul 11, 2022
Hashkill - A fast hash decryptor with golang
Hashkill - A fast hash decryptor with golang

Hashkill ♻️ Changelog v0.2 Added timing Fixed running, the program breaks if all

Mar 24, 2022
A tool that creates requests with the given urls and converts its response to md5 hash.

Response Converter A tool that creates requests with the given urls and converts its response to md5 hash. Prerequisites Before you begin you must hav

Nov 20, 2022
Jan 7, 2023
`age-plugin-yubikey` implementation, encrypt things with a Yubikey/any PIV card

This is an age plugin for PIV cards/Yubikey. Your secret is kept safe on the tamperproof hardware, while letting you use the age command-line.

Aug 10, 2022
Get any cryptocurrencies ticker and trade data in real time from multiple exchanges and then save it in multiple storage systems.
Get any cryptocurrencies ticker and trade data in real time from multiple exchanges and then save it in multiple storage systems.

Cryptogalaxy is an app which will get any cryptocurrencies ticker and trade data in real time from multiple exchanges and then saves it in multiple storage systems.

Jan 4, 2023