I have to encrypt a piece of text using Ruby. I've used the Ruby-Openssl gem for that purpose. This encrypted text is them passed to a python program using which I have to decrypt it. I've used Pycrypto for the purpose.
The problem is, in Pycrypto we have to specify the padding convention manually. In Ruby, the padding is done automatically. I'm using AES-CBC block cipher mode. This padding causes problems as its stripping cannot be performed properly in Python. As an example, these are the base64 encodings of an encrypted text in both Ruby and Python:
Python: aENJY28lvE89yY2T/te8vWwdeoeSqSwwlrOAv7b3AWw=
Ruby: aENJY28lvE89yY2T/te8vVoQE6JNxdSRgYXC8mqF3nI=
Please help...
OpenSSL applies PKCS#5Padding by default, so this is also used automatically when encrypting data with OpenSSL::Cipher
in AES-CBC mode (cf. OpenSSL docs). So there's no need to perform manual padding when using Ruby.
The padding has to be done manually in Python when using PyCrypto.
Once you apply this padding scheme in Python, both encrypted Base64 strings should match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With