init
This commit is contained in:
25
utils/crypto.go
Normal file
25
utils/crypto.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user