3 Star 9 Fork 4

haming123 / wxpay4go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
base_aes_gcm.go 704 Bytes
一键复制 编辑 原始数据 按行查看 历史
haming 提交于 2022-03-03 13:19 . init
package wxpay
import (
"crypto/aes"
"crypto/cipher"
"encoding/base64"
)
//使用 AEAD_AES_256_GCM 算法进行解密
//你可以使用此算法完成微信支付平台证书和回调报文解密
func DecryptAES256GCM(aesKey, associatedData, nonce, ciphertext string) (string, error) {
decodedCiphertext, err := base64.StdEncoding.DecodeString(ciphertext)
if err != nil {
return "", err
}
c, err := aes.NewCipher([]byte(aesKey))
if err != nil {
return "", err
}
gcm, err := cipher.NewGCM(c)
if err != nil {
return "", err
}
dataBytes, err := gcm.Open(nil, []byte(nonce), decodedCiphertext, []byte(associatedData))
if err != nil {
return "", err
}
return string(dataBytes), nil
}
Go
1
https://gitee.com/haming123/wxpay4go.git
git@gitee.com:haming123/wxpay4go.git
haming123
wxpay4go
wxpay4go
master

搜索帮助