I am trying to decrypt a bunch of passwords for database migration. I have old Rails code (actually a Runner script) that decrypts them just fine. But including the same code in the Rake task causes the task to crash with ... undefined method `to_a 'for" secretkey ": String ...
Why is the call to_a in a string not valid in the Rake task, but it works fine in the Runner script?
require 'openssl' KEY = 'secretkey' namespace :import do task :users => :environment do def decrypt_password(pw) cipher = OpenSSL::Cipher::Cipher.new('bf-ecb') cipher.decrypt cipher.key = KEY.to_a.pack('H*') <<--------- FAILS RIGHT HERE on to_a data = data.to_a.pack('H*') data = cipher.update(data) data << cipher.final unpad(data) end end ... other methods end
(Rails 3.0.0, Ruby 1.9.2)
yalestar
source share