Files
encryptx/hmacx/hmacx.go
T
2025-11-03 23:03:17 +08:00

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))
}