我正在尝试解密从AES_GCM生成的密文。密文是从golang中的“ crypto / aes”库生成的。现在,我正在尝试使用cryptodome库解密python中的加密文本。
func AESEncryption(key []byte, plaintext []byte)([]byte, error){
c, err := aes.NewCipher(key)
if err != nil {
log.Printf("Error ocurred in generating AES key %s", err)
return nil, err
}
gcm, err := cipher.NewGCM(c)
if err != nil {
return nil, err
}
nonce := make([]byte, gcm.NonceSize())
if _, err = io.ReadFull(rand.Reader, nonce); err != nil {
log.Printf("Error ocurred in generating AES key %s", err)
return nil, err
}
return gcm.Seal(nonce, nonce, plaintext, nil), nil
}
plainText:=“我将成为我应得的,有没有类似freewil的东西?”
十六进制编码的密钥: e629ed98829a893899ddda67f582ede72e2a187dd1ddd5ada54f49cfe2c8675f
十六进制编码的加密文本= 9012a33bfb0a51dec4f96404cdd7300ec6afca1fa0d6679a7c036652d014a38faf909e9c44d08dffac121aa85d48b7256fa74542e2545e27dc070adfc03af26f2a32f50c2c311d5c91ff6de2ca3b4347 解密golang中的加密文本可以成功执行,但不能在python中执行。
用于python解密的代码。
cipher = AES.new(binascii.unhexlify(key), AES.MODE_GCM)
cipher.nonce = binascii.unhexlify(nonce)
cipher.decrypt(binascii.unhexlify(hex_encoded_encrypted_hex))
答案 0 :(得分:1)
对我来说就像是一种魅力。
operator<<
显示
from Crypto.Cipher import AES
import binascii
key = binascii.unhexlify('e629ed98829a893899ddda67f582ede72e2a187dd1ddd5ada54f49cfe2c8675f')
data = binascii.unhexlify('9012a33bfb0a51dec4f96404cdd7300ec6afca1fa0d6679a7c036652d014a38faf909e9c44d08dffac121aa85d48b7256fa74542e2545e27dc070adfc03af26f2a32f50c2c311d5c91ff6de2ca3b4347da70669575c9b198f4')
nonce, tag = data[:12], data[-16:]
cipher = AES.new(key, AES.MODE_GCM, nonce)
cipher.decrypt_and_verify(data[12:-16], tag)