Skip to content

Commit

Permalink
feat:增加AEAD_AES_256_GCM解密算法
Browse files Browse the repository at this point in the history
  • Loading branch information
WJPone committed Jul 26, 2023
1 parent 2ce218a commit 9939464
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion encry/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ func DesEncryptECB(src, key string) string {
return fmt.Sprintf("%X", out)
}


//ECB解密
//参数src:要解密的数据
//参数key:密钥,长度必须是8位数不能超过
Expand Down Expand Up @@ -474,3 +473,23 @@ func Rsa2(origData string, block []byte) (sign string) {
sign = base64.StdEncoding.EncodeToString(s)
return
}
//AEAD_AES_256_GCM 解密
func DecryptAeAdAes256Gcm(ciphertext, nonce, associatedData string, aesKey []byte) string {
decodedCiphertext, err := base64.StdEncoding.DecodeString(ciphertext)
if err != nil {
return ""
}
c, err := aes.NewCipher(aesKey)
if err != nil {
return ""
}
gcm, err := cipher.NewGCM(c)
if err != nil {
return ""
}
dataBytes, err := gcm.Open(nil, []byte(nonce), decodedCiphertext, []byte(associatedData))
if err != nil {
return ""
}
return string(dataBytes)
}

0 comments on commit 9939464

Please sign in to comment.