engine/utils/crypto.go

26 lines
404 B
Go
Raw Normal View History

2024-02-11 01:31:01 +08:00
package utils
import (
"crypto/hmac"
"crypto/md5"
"crypto/sha256"
"encoding/hex"
"fmt"
)
//Md5 .
func Md5(src string) string {
data := []byte(src)
has := md5.Sum(data)
md5str := fmt.Sprintf("%x", has)
return md5str
}
func Sha256(src, privateKey string) string {
s := []byte(src)
key := []byte(privateKey)
m := hmac.New(sha256.New, key)
m.Write(s)
return hex.EncodeToString(m.Sum(nil))
}