hmacsha256.go 334 B

1234567891011121314151617
  1. package utils
  2. import (
  3. "crypto/hmac"
  4. "crypto/sha256"
  5. "encoding/base64"
  6. "encoding/hex"
  7. )
  8. func HmacSha256Encode(strings string, secret string) string {
  9. key := []byte(secret)
  10. h := hmac.New(sha256.New, key)
  11. h.Write([]byte(strings))
  12. sha := hex.EncodeToString(h.Sum(nil))
  13. return base64.StdEncoding.EncodeToString([]byte(sha))
  14. }