zmd5

package
v0.0.0-alpha.16 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualSum

func EqualSum(b []byte, sum []byte) bool

EqualSum compares MD5 hash. It returns if the sum matches to the hash of b.

func HMACEqualSum

func HMACEqualSum(msg, key, sum []byte) bool

HMACEqualSum compares HMAC-MD5 hash. It returns if the sum matches to the hash of msg.

func HMACSum

func HMACSum(msg, key []byte) []byte

HMACSum returns HMAC-MD5 hash. It uses crypto/md5.New.

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/aileron-projects/go/zcrypto/zmd5"
)

func main() {
	// Calculate HMAC-MD5 hash.
	// Validation data can be generated with:
	// 	- echo -n "Hello Go!" | openssl dgst -hmac "secret-key" -md5

	key := []byte("secret-key")
	sum := zmd5.HMACSum([]byte("Hello Go!"), key)
	encoded := hex.EncodeToString(sum)
	fmt.Println(len(sum), encoded)
	fmt.Println("`Hello Go!` match?", zmd5.HMACEqualSum([]byte("Hello Go!"), key, sum))
	fmt.Println("`Bye Go!` match?", zmd5.HMACEqualSum([]byte("Bye Go!"), key, sum))
}
Output:

16 951010d3df8a7f9a2e1ea2a8db158dc6
`Hello Go!` match? true
`Bye Go!` match? false

func Sum

func Sum(b []byte) []byte

Sum returns MD5 hash. It uses crypto/md5.New.

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/aileron-projects/go/zcrypto/zmd5"
)

func main() {
	// Calculate MD5 hash.
	// Validation data can be generated with:
	// 	- echo -n "Hello Go!" | openssl dgst -md5

	sum := zmd5.Sum([]byte("Hello Go!"))
	encoded := hex.EncodeToString(sum)
	fmt.Println(len(sum), encoded)
	fmt.Println("`Hello Go!` match?", zmd5.EqualSum([]byte("Hello Go!"), sum))
	fmt.Println("`Bye Go!` match?", zmd5.EqualSum([]byte("Bye Go!"), sum))
}
Output:

16 73a6333befc4397176b63dd4540ad5fe
`Hello Go!` match? true
`Bye Go!` match? false

Types

This section is empty.

Jump to

Keyboard shortcuts

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