Ai
1 Star 0 Fork 0

邢楠/toolbox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
hash.go 970 Bytes
一键复制 编辑 原始数据 按行查看 历史
邢楠 提交于 2021-06-28 11:02 +08:00 . # 163
package com
/**
* @Author : xingnan
* @Email : 457415936@qq.com
* @Time : 15:35
* @File : hash.go
* @Project : toolbox
* @Description : GoLand
*/
import (
"crypto/hmac"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
"fmt"
)
func Md5(value string) string {
h := md5.New()
h.Write([]byte(value))
return fmt.Sprintf("%s", hex.EncodeToString(h.Sum(nil)))
}
func Hmac(key, data string) string {
h := hmac.New(md5.New, []byte(key))
h.Write([]byte(data))
return hex.EncodeToString(h.Sum([]byte("")))
}
func HmacSha256(secret string, data string) string {
h := hmac.New(sha256.New, []byte(secret))
h.Write([]byte(data))
return hex.EncodeToString(h.Sum(nil))
}
//sha1加密
func Sha1(s string) string {
h := sha1.New()
h.Write([]byte(s))
rs := hex.EncodeToString(h.Sum(nil))
return rs
}
func ToSha1(s string) string {
h := sha1.New()
h.Write([]byte(s))
rs := hex.EncodeToString(h.Sum(nil))
return rs
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xingnan/toolbox.git
git@gitee.com:xingnan/toolbox.git
xingnan
toolbox
toolbox
v0.1.81

搜索帮助