1 Star 0 Fork 0

wosylf/龙飞工具仓库

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
aes_gcm_encrypt.go 661 Bytes
一键复制 编辑 原始数据 按行查看 历史
longfei 提交于 2024-07-14 14:54 +08:00 . 初始化一下
package aes
import (
"crypto/aes"
"crypto/cipher"
"fmt"
"gitee.com/wosylf/ltool/pkg/util"
)
func GCMEncrypt(originText, additional, key []byte) (nonce []byte, cipherText []byte, err error) {
return gcmEncrypt(originText, additional, key)
}
func gcmEncrypt(originText, additional, key []byte) ([]byte, []byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
return nil, nil, err
}
nonce := []byte(util.GetRandomString(12))
gcm, err := cipher.NewGCM(block)
if err != nil {
return nil, nil, fmt.Errorf("cipher.NewGCM(),error:%w", err)
}
cipherBytes := gcm.Seal(nil, nonce, originText, additional)
return nonce, cipherBytes, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wosylf/ltool.git
git@gitee.com:wosylf/ltool.git
wosylf
ltool
龙飞工具仓库
46283b34d5bc

搜索帮助