This commit is contained in:
zhaoxiaorong
2025-02-07 13:01:38 +08:00
parent ebcdfe1ee8
commit 57a0d8ae81
52 changed files with 3313 additions and 0 deletions

25
utils/crypto.go Normal file
View File

@@ -0,0 +1,25 @@
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))
}