Inconsistent AES-CFB Encryption Results between Go and Pycrypto
Utilizing AES-CFB encryption, varying results are obtained upon comparison between Go and Pycrypto. To investigate this discrepancy, we analyze the provided code samples.
In Python, Crypto.Cipher.AES utilizes MODE_CFB with an explicitly specified initial vector (IV). Conversely, in Go, aes.NewCipher requires explicit creation of an AES block cipher and subsequent instantiation of CFBEncrypter or CFBDecrypter with the desired IV.
A critical distinction between the two implementations lies in their treatment of segment size. Pycrypto operates on 8-bit segments, known as CFB8, while Go uses 16-bit segments by default. This difference leads to the observed divergence in encryption outcomes.
Adapting Go to Python's CFB8 Approach
To allow Go to decrypt ciphertext encrypted by Pycrypto with CFB8 settings, the source code for Go's CFBDecrypter can be modified. Specifically, the XORKeyStream method can be adapted to handle 8-bit segments.
This modification would enable Go to decryptciphertext encrypted using Pycrypto's specific AES-CFB8 parameters, fostering interoperability between the two languages in handling encryption and decryption tasks.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3