完善其他类型的加解密

This commit is contained in:
Yun
2025-11-03 23:03:17 +08:00
parent 8bcdc16955
commit 3dd73f928d
6 changed files with 831 additions and 59 deletions
+22
View File
@@ -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))
}