zsha256

package
v0.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualSum224

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

EqualSum224 compares SHA256/224 hash. It returns if the sum matches to the hash of b.

func EqualSum256

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

EqualSum256 compares SHA256 hash. It returns if the sum matches to the hash of b.

func HMACEqualSum224

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

HMACEqualSum224 compares HMAC-SHA256/224 hash. It returns if the sum matches to the hash of b.

func HMACEqualSum256

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

HMACEqualSum256 compares HMAC-SHA256 hash. It returns if the sum matches to the hash of b.

func HMACSum224

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

HMACSum224 returns HMAC-SHA256/224 hash. It uses crypto/sha256.New224.

Example
package main

import (
	"encoding/hex"
	"fmt"

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

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

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

28 1e8a9de1ec6ba6c1223a95c2ce34679de9f93ac0cc764b4cbf170f0a
`Hello Go!` match? true
`Bye Go!` match? false

func HMACSum256

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

HMACSum256 returns HMAC-SHA256 hash. It uses crypto/sha256.New.

Example
package main

import (
	"encoding/hex"
	"fmt"

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

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

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

32 95f09ba10c62fe594ed3439c707c28f44f611547857c0720823a7636dae851c2
`Hello Go!` match? true
`Bye Go!` match? false

func Sum224

func Sum224(b []byte) []byte

Sum224 returns SHA256/224 hash. It uses crypto/sha256.New224.

Example
package main

import (
	"encoding/hex"
	"fmt"

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

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

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

28 58a808579d6f7c610cd462d89564c502e45db9c45ed4b376303af7a8
`Hello Go!` match? true
`Bye Go!` match? false

func Sum256

func Sum256(b []byte) []byte

Sum256 returns SHA256 hash. It uses crypto/sha256.New.

Example
package main

import (
	"encoding/hex"
	"fmt"

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

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

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

32 040bf11d7b007ee960e2b0bed48db8e729c2ba8f1efd649505332c40541673cd
`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