token.go 267 B

1234567891011121314151617
  1. package utils
  2. import (
  3. "crypto/hmac"
  4. "crypto/sha1"
  5. "encoding/hex"
  6. )
  7. const (
  8. hmac_key = "hmac_key_"
  9. )
  10. func GenerateToken(plain string) string {
  11. hash := hmac.New(sha1.New, []byte(hmac_key))
  12. hash.Write([]byte(plain))
  13. return hex.EncodeToString(hash.Sum(nil))
  14. }