23 lines
485 B
Go
23 lines
485 B
Go
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))
|
|
}
|