| 12345678910111213141516171819202122232425262728293031323334 |
- package utl
- import (
- "crypto/hmac"
- "crypto/md5"
- "crypto/sha1"
- "crypto/sha256"
- "encoding/hex"
- )
- var (
- hmac256key = []byte("kettle-hmac-key@2021#gl")
- )
- func Md5(text string) string {
- h := md5.Sum([]byte(text))
- return hex.EncodeToString(h[:])
- }
- func Sha1(text string) string {
- h := sha1.Sum([]byte(text))
- return hex.EncodeToString(h[:])
- }
- func Sha256(text string) string {
- h := sha256.Sum256([]byte(text))
- return hex.EncodeToString(h[:])
- }
- func Hmac256(text string) string {
- h := hmac.New(sha256.New, hmac256key)
- h.Write([]byte(text))
- return hex.EncodeToString(h.Sum(nil))
- }
|