I am trying to encrypt text using AES-256-CBC with Crypto Js (on the client side) and OpenSSL in rails (on the server side) and they are giving me different results. This explains why I cannot decode the encrypted text on the server side and vice-versa on the client side.
Here is how I am doing it:
Client Side (Crypto JS) - Edited
iv = CryptoJS.enc.Base64.parse("kT+uMuPwUk2LH4cFbK0GiA==")
key = CryptoJS.enc.Hex.parse("6476b3f5ec6dcaddb637e9c9654aa687")
encrypted_text = CryptoJS.AES.encrypt("test", key, {mode: CryptoJS.mode.CBC, formatter : Base64Formatter, iv : iv})
encrypted_text => "7Qu7/V7yXHt67wMOV0/1Tg=="
Server Side (Rails OpenSSL) - Edited
iv = Base64.decode64("kT+uMuPwUk2LH4cFbK0GiA==")
key = "6476b3f5ec6dcaddb637e9c9654aa687"
cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
cipher.encrypt
cipher.key = key
cipher.iv = iv
text = cipher.update("test") + cipher.final
encrypted_text = Base64.strict_encode64(text)
encrypted_text => "fHhNBuopuuthdq2SFvvgDw=="
Does anyone have any idea as to what I am doing wrong? I am just stumped at this point.
Help is much appreciated..thanks!
Paul