1 Star 0 Fork 0

Teval/uts

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
hash.go 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
Teval 提交于 2024-03-12 01:13 +08:00 . 添加HmacSha1算法
package uts
import (
"crypto/hmac"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/google/uuid"
)
// Md5 []byte转md5
func Md5(b []byte) string {
return fmt.Sprintf("%x", md5.Sum(b))
}
// HmacMd5 []byte转md5
func HmacMd5(key, data []byte) string {
h := hmac.New(md5.New, key)
h.Write(data)
return fmt.Sprintf("%x", h.Sum([]byte{}))
}
// Sha1 Sha1加密
func Sha1(b []byte) string {
h := sha1.New()
h.Write(b)
return hex.EncodeToString(h.Sum(nil))
}
// HmacSha1 HmacSha1加密
func HmacSha1(secret, data []byte) string {
h := hmac.New(sha1.New, secret)
h.Write(data)
return hex.EncodeToString(h.Sum(nil))
}
// Sha256 Sha256加密
func Sha256(b []byte) string {
var h = sha256.New()
h.Write(b)
return fmt.Sprintf("%x", h.Sum(nil))
}
// HmacSha256 HmacSha256加密
func HmacSha256(secret, data []byte) string {
h := hmac.New(sha256.New, secret)
h.Write(data)
return hex.EncodeToString(h.Sum(nil))
}
// UUID 生成UUID
func UUID() string {
return uuid.New().String()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/teval/uts.git
git@gitee.com:teval/uts.git
teval
uts
uts
a1699f1f2aaf

搜索帮助