Documentation
¶
Index ¶
- func EqualSum224(b []byte, sum []byte) bool
- func EqualSum256(b []byte, sum []byte) bool
- func HMACEqualSum224(msg, key, sum []byte) bool
- func HMACEqualSum256(msg, key, sum []byte) bool
- func HMACSum224(msg, key []byte) []byte
- func HMACSum256(msg, key []byte) []byte
- func Sum224(b []byte) []byte
- func Sum256(b []byte) []byte
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EqualSum224 ¶
EqualSum224 compares SHA256/224 hash. It returns if the sum matches to the hash of b.
func EqualSum256 ¶
EqualSum256 compares SHA256 hash. It returns if the sum matches to the hash of b.
func HMACEqualSum224 ¶
HMACEqualSum224 compares HMAC-SHA256/224 hash. It returns if the sum matches to the hash of b.
func HMACEqualSum256 ¶
HMACEqualSum256 compares HMAC-SHA256 hash. It returns if the sum matches to the hash of b.
func HMACSum224 ¶
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 ¶
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 ¶
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 ¶
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.
Click to show internal directories.
Click to hide internal directories.