attr_encrypted: OpenSSL::Cipher::CipherError: wrong final block length

Gosh - I can’t win - the column is encrypted in the DB (yay) but now I’m getting this when trying to decrypt:

ruby-1.9.2-p290 :009 > u.dob

OpenSSL::Cipher::CipherError: wrong final block length from /Users/northband/.rvm/gems/ruby-1.9.2-p290/gems/encryptor-1.1.3/lib/encryptor.rb:62:in final' from /Users/northband/.rvm/gems/ruby-1.9.2-p290/gems/encryptor-1.1.3/lib/encryptor.rb:62:incrypt’ from /Users/northband/.rvm/gems/ruby-1.9.2-p290/gems/encryptor-1.1.3/lib/encryptor.rb:44:in decrypt' from /Users/northband/.rvm/gems/ruby-1.9.2-p290/gems/attr_encrypted-1.2.1/lib/attr_encrypted.rb:179:indecrypt’ from /Users/northband/.rvm/gems/ruby-1.9.2-p290/gems/attr_encrypted-1.2.1/lib/attr_encrypted.rb:262:in decrypt' from /Users/northband/.rvm/gems/ruby-1.9.2-p290/gems/attr_encrypted-1.2.1/lib/attr_encrypted.rb:126:inblock (2 levels) in attr_encrypted’ from (irb):9 from /Users/northband/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in start' from /Users/northband/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.8/lib/rails/commands/console.rb:8:instart’ from /Users/northband/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.8/lib/rails/commands.rb:41:in <top (required)>' from script/rails:6:inrequire’ from script/rails:6:in `<main>’

Any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

Try setting the cipher.key value after calling the decrypt or encrypt methods

I got this error before. Make sure that you’re not setting your encrypted attribute directly, and also make sure the key you’re using is ok. I just searched google for a random 256 key generator and used that key.