Files
hash/hash.go
T
2023-10-10 21:56:53 +01:00

28 lines
573 B
Go

package hash
import (
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
)
// SHA256 creates a hex-encoded SHA256 checksum for a string input.
func SHA256(value string) string {
b := sha256.Sum256([]byte(value))
hash := []byte{}
for _, byte := range b {
hash = append(hash, byte)
}
return hex.EncodeToString(hash)
}
// SHA512 creates a hex-encoded SHA512 checksum for a string input.
func SHA512(value string) string {
b := sha512.Sum512([]byte(value))
hash := []byte{}
for _, byte := range b {
hash = append(hash, byte)
}
return hex.EncodeToString(hash)
}