完善其他类型的加解密
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package hmacx
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
// HMAC-SHA256 计算消息认证码
|
||||
func HMACSHA256(message, key string) string {
|
||||
mac := hmac.New(sha256.New, []byte(key))
|
||||
mac.Write([]byte(message))
|
||||
return hex.EncodeToString(mac.Sum(nil))
|
||||
}
|
||||
|
||||
// HMAC-SHA512 计算消息认证码
|
||||
func HMACSHA512(message, key string) string {
|
||||
mac := hmac.New(sha512.New, []byte(key))
|
||||
mac.Write([]byte(message))
|
||||
return hex.EncodeToString(mac.Sum(nil))
|
||||
}
|
||||
Reference in New Issue
Block a user