hasher.go 593 B

12345678910111213141516171819202122232425262728293031323334
  1. package utl
  2. import (
  3. "crypto/hmac"
  4. "crypto/md5"
  5. "crypto/sha1"
  6. "crypto/sha256"
  7. "encoding/hex"
  8. )
  9. var (
  10. hmac256key = []byte("kettle-hmac-key@2021#gl")
  11. )
  12. func Md5(text string) string {
  13. h := md5.Sum([]byte(text))
  14. return hex.EncodeToString(h[:])
  15. }
  16. func Sha1(text string) string {
  17. h := sha1.Sum([]byte(text))
  18. return hex.EncodeToString(h[:])
  19. }
  20. func Sha256(text string) string {
  21. h := sha256.Sum256([]byte(text))
  22. return hex.EncodeToString(h[:])
  23. }
  24. func Hmac256(text string) string {
  25. h := hmac.New(sha256.New, hmac256key)
  26. h.Write([]byte(text))
  27. return hex.EncodeToString(h.Sum(nil))
  28. }