I need to do encryption and decryption in my rails application. I try to use ezcrypto, but whenever I do the decryption, I get this error.
OpenSSL::Cipher::CipherError in ProfilesController
wrong final block length
What needs to be changed to stop this error. I tried using another openssl implementation like this (methods that will be called from my model)
def encrypt_attr(unencrypted)
c = OpenSSL::Cipher.new("aes-256-cbc")
c.encrypt
c.key = Digest::SHA1.hexdigest('pass')
e = c.update(unencrypted)
e << c.final
return e
end
def decrypt_attr(encrypted_attr)
if encrypted_attr != ""
c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
c.decrypt
c.key = Digest::SHA1.hexdigest('pass')
d = c.update(encrypted_attr)
d << c.final
return d
end
end
It gives the same decryption error. How can I do encryption and decryption, and not get this openssl error.
source
share