Documentation ¶
Overview ¶
Package hasher is a utility wrapper around some common hashing functions with customizable encoding
Supported encodings ¶
Base64, Base64UrlSafe, Base32, Hex, Custom Encoding Function ¶
If an encoding is supplied that is not recognised an "unsupported encoding" error will be returned with an empty string in the hash value, so it is recommended to use the constants supplied with this package
Index ¶
- func Equal(h1, h2 []byte) bool
- type Hash
- func HmacMd5(data []byte, secret string) Hash
- func HmacSha1(data []byte, secret string) Hash
- func HmacSha256(data []byte, secret string) Hash
- func HmacSha512(data []byte, secret string) Hash
- func Md5(data []byte) Hash
- func Sha1(data []byte) Hash
- func Sha256(data []byte) Hash
- func Sha3(data []byte) Hash
- func Sha512(data []byte) Hash
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Hash ¶ added in v1.0.0
type Hash []byte
Hash allows the addition of encoding functions to the hashed data
func HmacMd5 ¶ added in v1.0.0
HmacMd5 returns a new HMAC hash using md5.
Example ¶
h := HmacMd5([]byte("hello"), "secretKey").Base64() fmt.Println(h)
Output:
func HmacSha1 ¶ added in v1.0.0
HmacSha1 returns a new HMAC hash using sha1.
Example ¶
h := HmacSha1([]byte("hello"), "secretKey").Base64() fmt.Println(h)
Output:
func HmacSha256 ¶ added in v1.0.0
HmacSha256 returns a new HMAC hash using sha256.
Example ¶
h := HmacSha256([]byte("hello"), "secretKey").Base64() fmt.Println(h)
Output:
func HmacSha512 ¶ added in v1.0.0
HmacSha512 returns a new HMAC hash using sha512.
Example ¶
h := HmacSha512([]byte("hello"), "secretKey").Base64() fmt.Println(h)
Output:
func Md5 ¶
Md5 returns a md5 checksum
Example ¶
h := Md5([]byte("hello")).Hex() fmt.Println(h)
Output:
func Sha1 ¶
Sha1 returns a sha1 checksum
Example ¶
h := Sha1([]byte("hello")).Hex() fmt.Println(h)
Output:
func Sha256 ¶
Sha256 returns a sha2-256 checksum
Example ¶
h := Sha256([]byte("hello")).Hex() fmt.Println(h)
Output:
func Sha3 ¶
Sha3 returns a sha3-256 checksum using the ShakeSum256 function
Example ¶
h := Sha3([]byte("hello")).Hex() fmt.Println(h)
Output:
func Sha512 ¶
Sha512 returns a sha2-512 checksum
Example ¶
h := Sha512([]byte("hello")).Hex() fmt.Println(h)
Output:
func (Hash) Base32 ¶ added in v1.0.0
Base32 returns a string representation of the hash in base32 encoding
Example ¶
h := Sha1([]byte("hello")).Base32() fmt.Println(h)
Output:
func (Hash) Base64 ¶ added in v1.0.0
Base64 returns a string representation of the hash in base64 encoding
Example ¶
h := Sha512([]byte("hello")).Base64() fmt.Println(h)
Output:
func (Hash) Base64UrlSafe ¶ added in v1.0.0
Base64UrlSafe returns a string representation of the hash in Base64UrlSafe encoding
Example ¶
h := Sha512([]byte("hello")).Base64UrlSafe() fmt.Println(h)
Output: