1 Star 1 Fork 1

up-zero/gotool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
hmac.go 751 Bytes
一键复制 编辑 原始数据 按行查看 历史
GetcharZp 提交于 2023-08-17 15:54 +08:00 . feat jwt, hmac
package gotool
import (
"crypto"
"crypto/hmac"
)
// hmacGenerate 计算 HMAC
//
// data 数据
// key 密钥
// hash 哈希算法
func hmacGenerate(data, key []byte, hash crypto.Hash) []byte {
h := hmac.New(hash.New, key)
h.Write(data)
return h.Sum(nil)
}
// HmacSHA256 计算 SHA256
//
// data 数据
// key 密钥
func HmacSHA256(data []byte, key []byte) []byte {
return hmacGenerate(data, key, crypto.SHA256)
}
// HmacSHA384 计算 HmacSHA384
//
// data 数据
// key 密钥
func HmacSHA384(data []byte, key []byte) []byte {
return hmacGenerate(data, key, crypto.SHA384)
}
// HmacSHA512 计算 HmacSHA512
//
// data 数据
// key 密钥
func HmacSHA512(data []byte, key []byte) []byte {
return hmacGenerate(data, key, crypto.SHA512)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/up-zero/gotool.git
git@gitee.com:up-zero/gotool.git
up-zero
gotool
gotool
main

搜索帮助