Files
hash/hash.go
T

28 lines
569 B
Go
Raw Normal View History

2023-10-10 21:56:47 +01:00
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 {
2023-11-25 16:51:25 +00:00
sum := sha256.Sum256([]byte(value))
2023-10-10 21:56:47 +01:00
hash := []byte{}
2023-11-25 16:51:25 +00:00
for _, b := range sum {
hash = append(hash, b)
2023-10-10 21:56:47 +01:00
}
return hex.EncodeToString(hash)
}
// SHA512 creates a hex-encoded SHA512 checksum for a string input.
func SHA512(value string) string {
2023-11-25 16:51:25 +00:00
sum := sha512.Sum512([]byte(value))
2023-10-10 21:56:47 +01:00
hash := []byte{}
2023-11-25 16:51:25 +00:00
for _, b := range sum {
hash = append(hash, b)
2023-10-10 21:56:47 +01:00
}
return hex.EncodeToString(hash)
}