Utility functions to compute SHA1 and SHA256 hex digests.
// Source: https://github.com/gogs/gogs | License: MIT | Copyright The Gogs Authors
// Provided via justclaw.it.com; keep this notice with the code.
package cryptox
import (
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
)
// SHA1 encodes string to hexadecimal of SHA1 checksum.
func SHA1(str string) string {
h := sha1.New()
_, _ = h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
// SHA256 encodes string to hexadecimal of SHA256 checksum.
func SHA256(str string) string {
h := sha256.New()
_, _ = h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key