1 Star 0 Fork 0

Darwin/go-tools

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
encrypt.go 699 Bytes
一键复制 编辑 原始数据 按行查看 历史
Darwin 提交于 2025-05-08 18:18 +08:00 . feat:add hertz/kitex tools
package crypto
import (
"crypto/hmac"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
"fmt"
"hash"
)
func SHA1(content []byte) string {
h := sha1.New()
h.Write(content)
return hex.EncodeToString(h.Sum(nil))
}
func SHA512(content []byte) string {
h := sha512.New()
h.Write(content)
return hex.EncodeToString(h.Sum(nil))
}
func MD5(content []byte) string {
return fmt.Sprintf("%x", md5.Sum(content))
}
func Hmac(key, content []byte, hFunc func() hash.Hash) string {
h := hmac.New(hFunc, key)
h.Write(content)
return hex.EncodeToString(h.Sum(nil))
}
func EncodePwd(password, ak string) string {
return Hmac([]byte(ak), []byte(password), sha256.New)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/byx_darwin/go-tools.git
git@gitee.com:byx_darwin/go-tools.git
byx_darwin
go-tools
go-tools
3df7fcace024

搜索帮助