I have the following code in Python that works well. It decrypts the data in the variable encrypted_data using the mcrypt module. I want to perform the same operations in Ruby. Therefore I required the openssl module. Unfortunately the Ruby version does not work. This is the error:
`final': bad decrypt (OpenSSL::Cipher::CipherError)
EDIT I created a GitHub repository for you to test this. Download the sourcecode here: github.com/ph3nx/ruby-decrypt
EDIT 2
The bad decrypt error does not appear anymore. I fixed this by setting d.padding = 0. Problem is: the decrypted data is still not correct. I can't view the image.
If you need additional Information about my system or anything else feel free to ask. Any help is highly appreciated. Thanks!
Python
import base64
import mcrypt
encrypted_data = "placeholder: This is the encrypted data."
key = base64.b64decode("6vYJkO5beHNlwOm+aMqUTTzSpRw9jR3faHqu0wVoAG0=")
iv = base64.b64decode("EbuuKuVF4+DzDbWsvQi/ZA==")
m = mcrypt.MCRYPT("rijndael-128", "cbc")
m.init(key, iv)
decrypted_data = m.decrypt(encrypted_data)
Ruby
require 'base64'
require 'openssl'
encrypted_data = "placeholder: This is the encrypted data."
key = Base64.decode64("6vYJkO5beHNlwOm+aMqUTTzSpRw9jR3faHqu0wVoAG0=")
iv = Base64.decode64("EbuuKuVF4+DzDbWsvQi/ZA==")
d = OpenSSL::Cipher::AES128.new :CBC
d.decrypt
d.padding = 0
d.key = key
d.iv = iv
decrypted_data = d.update(encrypted_data) << d.final
d.padding = 0, from here: stackoverflow.com/questions/19661508/…