hash.go 573 B

123456789101112131415161718192021222324252627
  1. package hash
  2. import (
  3. "crypto/sha256"
  4. "crypto/sha512"
  5. "encoding/hex"
  6. )
  7. // SHA256 creates a hex-encoded SHA256 checksum for a string input.
  8. func SHA256(value string) string {
  9. b := sha256.Sum256([]byte(value))
  10. hash := []byte{}
  11. for _, byte := range b {
  12. hash = append(hash, byte)
  13. }
  14. return hex.EncodeToString(hash)
  15. }
  16. // SHA512 creates a hex-encoded SHA512 checksum for a string input.
  17. func SHA512(value string) string {
  18. b := sha512.Sum512([]byte(value))
  19. hash := []byte{}
  20. for _, byte := range b {
  21. hash = append(hash, byte)
  22. }
  23. return hex.EncodeToString(hash)
  24. }