Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 & Encrypted Strings Gem - getting OpenSSL::Cipher::CipherError: bad decrypt error

I am using rails 3.2, Ruby 1.9.3 and the encrypted_strings gem, when try the following:

"wC6234sdf234234cCY1Lag==\n".decrypt(:symmetric, :key => "mykeynottelling")

I get this error:

OpenSSL::Cipher::CipherError: bad decrypt

This does not however happen with Ruby 1.8.7. I'm a little lost on this, does anyone see what might be causing this?

UPDATE 1:

If I encrypt a string in ruby 1.8.7:

"password".encrypt(:symmetric, :key => "www.buyandsell.ie") # output is "hr0aZUZTa7x1gQL8ZMI/dQ==\n"

and try to decrypt that in ruby 1.9.2 I get a "bad decrypt" error, but I if paste it into my IRB console in ruby 1.8.7 and try to decrypt it, it works.

Update 2:

OpenSSL is different between my ruby 1.9.3 and 1.8.7 boxes, could this cause this error?

like image 485
Jason Avatar asked Jun 13 '13 18:06

Jason


1 Answers

I had a similar issue upgrading from 1.9.3 to 2.2.2 dealing with the Symmetric Encryption gem. The root cause ended up being the fact that the gem used Ruby's marshaling library, which had changed between versions.

I ultimately had to decrypt all of the data in 1.9.3 before upgrading to 2.2.2, which proved to be a miserable experience.

From the docs,

Marshaled data has major and minor version numbers stored along with the object information. In normal use, marshaling can only load data written with the same major version number and an equal or lower minor version number.

like image 158
jtwarren Avatar answered Oct 11 '22 15:10

jtwarren