site
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
397 B

3 years ago
  1. package site
  2. import (
  3. "crypto/hmac"
  4. "fmt"
  5. "golang.org/x/crypto/ripemd160"
  6. )
  7. func EncryptedUserToken(token string, key ...string) string {
  8. var token_key string = USER_TOKEN_KEY
  9. if len(key) > 0 {
  10. token_key = key[0]
  11. }
  12. h2 := hmac.New(ripemd160.New, []byte(token_key))
  13. h2.Write([]byte(token))
  14. hashBytes := h2.Sum(nil)
  15. hashString := fmt.Sprintf("%x", hashBytes)
  16. return hashString
  17. }