Hi All,
I spent lots of time today trying to upgrade from 1.7.1 to 1.7.3, so
thought I’d share my findings in case someone else hits the same issue.
I
store values in a database encrypted, and was getting errors decrypting
once I upgraded.
I have a function:
def cipher(s, key, decrypt=false)
cipher = OpenSSL::Cipher::AES128.new(“CBC”)
cipher.decrypt if decrypt
cipher.key = key
response = “”
response << cipher.update(s)
response << cipher.final
end
Here’s the output from usage in 1.7.1:
key = OpenSSL::PKey::RSA.generate(1024)
…
x = cipher(“hi”, key.to_pem)
=> “\xA0\xF5+0\xCEWD\x96o\x95\xA6\b\x1D\xE1\xC0\xCD”
cipher(x, key.to_pem, true)
And here is the output from usage in 1.7.3
x = cipher(“hi”, key.to_pem)
=> “\xCB\x99\xD3\xC1\x8F\xC7\x82\xD7R\x10*{\xE6’\x1A\xB9”
cipher(x, key.to_pem, true)
=> “hi”
The difference is because of
https://jira.codehaus.org/browse/JRUBY-6951.
This change was made in 1.7.2 and changes the default of the IV for the
cipher. This means that if you’ve encrypted something in <1.7.1 without
setting a custom IV, you won’t be able to decrypt in >1.7.2 without
using
the old IV default (“OpenSSL for JRuby rulez!”).
Best,
Ben