hash

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 14 Imported by: 1

Documentation

Overview

Package hash provides hashing utilities:

  • Standard hashes: MD5, SHA-1, SHA-256, SHA-512
  • HMAC: HMAC-SHA256, HMAC-SHA512
  • CRC: CRC32, CRC64
  • MurmurHash3: 32-bit and 128-bit (x64) non-cryptographic hashes
  • xxHash: xxHash64 and xxHash32 non-cryptographic hashes
  • Hash file/stream helpers

Quick start

hash.MD5Hex([]byte("hello"))           // "5d41402abc4b2a76b9719d911017c592"
hash.SHA256Hex([]byte("hello"))
hash.HMACSHA256Hex([]byte("data"), key)
hash.Murmur3_32Hex([]byte("hello"), 0)
hash.XXHash64Hex([]byte("hello"), 0)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adler32

func Adler32(data []byte) uint32

Adler32 returns the Adler-32 checksum of data.

func CRC16

func CRC16(data []byte) uint16

CRC16 returns the CRC16-CCITT checksum of data.

func CRC16CCITT

func CRC16CCITT(data []byte) uint16

CRC16CCITT returns the CRC16-CCITT checksum of data (poly 0x1021).

func CRC16Hex

func CRC16Hex(data []byte) string

CRC16Hex returns the CRC16-CCITT checksum as a hex string.

func CRC32

func CRC32(data []byte) uint32

CRC32 returns the CRC32 checksum of data (IEEE polynomial).

func CRC32Hex

func CRC32Hex(data []byte) string

CRC32Hex returns the CRC32 checksum as a hex string.

func CRC64

func CRC64(data []byte) uint64

CRC64 returns the CRC64 checksum of data (ISO polynomial).

func CRC64Hex

func CRC64Hex(data []byte) string

CRC64Hex returns the CRC64 checksum as a hex string.

func FNV1a32

func FNV1a32(data []byte) uint32

FNV1a32 returns the FNV-1a 32-bit hash of data.

func FNV1a64

func FNV1a64(data []byte) uint64

FNV1a64 returns the FNV-1a 64-bit hash of data.

func HMACEqual

func HMACEqual(a, b []byte) bool

HMACEqual compares two HMAC values in constant time.

func HMACSHA256

func HMACSHA256(data, key []byte) []byte

HMACSHA256 returns the HMAC-SHA256 of data using key.

func HMACSHA256Hex

func HMACSHA256Hex(data, key []byte) string

HMACSHA256Hex returns the HMAC-SHA256 of data as a hex string.

func HMACSHA512

func HMACSHA512(data, key []byte) []byte

HMACSHA512 returns the HMAC-SHA512 of data using key.

func HMACSHA512Hex

func HMACSHA512Hex(data, key []byte) string

HMACSHA512Hex returns the HMAC-SHA512 of data as a hex string.

func Hex

func Hex(ht HashType, data []byte) (string, error)

Hex returns the hex hash of data using the specified algorithm.

func HexUpper

func HexUpper(ht HashType, data []byte) (string, error)

HexUpper returns the uppercase hex hash of data.

func MD5

func MD5(data []byte) []byte

MD5 returns the MD5 hash of data.

func MD5File

func MD5File(path string) ([]byte, error)

MD5File returns the MD5 hash of a file.

func MD5FileHex

func MD5FileHex(path string) (string, error)

MD5FileHex returns the MD5 hash of a file as a hex string.

func MD5Hex

func MD5Hex(data []byte) string

MD5Hex returns the MD5 hash of data as a lowercase hex string.

func MD5Reader

func MD5Reader(r io.Reader) ([]byte, error)

MD5Reader returns the MD5 hash of a reader.

func MD5String

func MD5String(s string) string

MD5String returns the MD5 hash of a string as a hex string.

func Murmur3_32

func Murmur3_32(data []byte, seed uint32) uint32

Murmur3_32 returns the MurmurHash3 32-bit hash of data with the given seed.

func Murmur3_32Hex

func Murmur3_32Hex(data []byte, seed uint32) string

Murmur3_32Hex returns the MurmurHash3 32-bit hash as a hex string.

func Murmur3_128

func Murmur3_128(data []byte, seed uint32) (uint64, uint64)

Murmur3_128 returns the MurmurHash3 128-bit hash (x64) as two uint64 values.

func Murmur3_128Hex

func Murmur3_128Hex(data []byte, seed uint32) string

Murmur3_128Hex returns the MurmurHash3 128-bit hash as a hex string.

func SHA1

func SHA1(data []byte) []byte

SHA1 returns the SHA-1 hash of data.

func SHA1Hex

func SHA1Hex(data []byte) string

SHA1Hex returns the SHA-1 hash of data as a lowercase hex string.

func SHA1String

func SHA1String(s string) string

SHA1String returns the SHA-1 hash of a string as a hex string.

func SHA256

func SHA256(data []byte) []byte

SHA256 returns the SHA-256 hash of data.

func SHA256File

func SHA256File(path string) ([]byte, error)

SHA256File returns the SHA-256 hash of a file.

func SHA256FileHex

func SHA256FileHex(path string) (string, error)

SHA256FileHex returns the SHA-256 hash of a file as a hex string.

func SHA256Hex

func SHA256Hex(data []byte) string

SHA256Hex returns the SHA-256 hash of data as a lowercase hex string.

func SHA256Reader

func SHA256Reader(r io.Reader) ([]byte, error)

SHA256Reader returns the SHA-256 hash of a reader.

func SHA256String

func SHA256String(s string) string

SHA256String returns the SHA-256 hash of a string as a hex string.

func SHA512

func SHA512(data []byte) []byte

SHA512 returns the SHA-512 hash of data.

func SHA512Hex

func SHA512Hex(data []byte) string

SHA512Hex returns the SHA-512 hash of data as a lowercase hex string.

func SHA512String

func SHA512String(s string) string

SHA512String returns the SHA-512 hash of a string as a hex string.

func XXHash32

func XXHash32(data []byte, seed uint32) uint32

XXHash32 returns the xxHash32 hash of data with the given seed.

func XXHash32Hex

func XXHash32Hex(data []byte, seed uint32) string

XXHash32Hex returns the xxHash32 hash as a hex string.

func XXHash64

func XXHash64(data []byte, seed uint64) uint64

XXHash64 returns the xxHash64 hash of data with the given seed.

func XXHash64Hex

func XXHash64Hex(data []byte, seed uint64) string

XXHash64Hex returns the xxHash64 hash as a hex string.

Types

type HashType

type HashType string

HashType represents a hash algorithm type.

const (
	HashMD5    HashType = "md5"
	HashSHA1   HashType = "sha1"
	HashSHA256 HashType = "sha256"
	HashSHA512 HashType = "sha512"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL