3 Star 2 Fork 1

洪流 / common

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
encryption.go 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
洪流 提交于 2022-10-18 15:47 . 完成第一版oss
/*
* @Author: hongliu
* @Date: 2022-10-17 15:51:23
* @LastEditors: hongliu
* @LastEditTime: 2022-10-17 15:53:01
* @FilePath: \common\utils\encryption.go
* @Description:数据编解码相关工具函数
*
* Copyright (c) 2022 by 洪流, All Rights Reserved.
*/
package utils
import (
"crypto/hmac"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
)
// HmacSha1 HmacSha1加密
func HmacSha1(data, secrect string) string {
mac := hmac.New(sha1.New, []byte(secrect))
mac.Write([]byte(data))
return base64.StdEncoding.EncodeToString(mac.Sum(nil))
}
// MD5WithBase64 先使用MD5加密 然后使用base64加密
func MD5WithBase64(data []byte) string {
content := md5.Sum(data)
return base64.StdEncoding.EncodeToString(content[:])
}
// Sha256hash sha256哈希编码
func Sha256hash(data []byte) string {
s := sha256.New()
s.Write(data)
return hex.EncodeToString(s.Sum(nil))
}
// HmacSha256加密
func HmacSha256(data, secret []byte) []byte {
mac := hmac.New(sha256.New, secret)
mac.Write(data)
return mac.Sum(nil)
}
Go
1
https://gitee.com/hongliu9527/common.git
git@gitee.com:hongliu9527/common.git
hongliu9527
common
common
v1.0.4

搜索帮助