From: Felipe Coury Date: 2009-03-24T14:31:51+09:00 Subject: Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby Giovanni / Rob, Thanks a lot for your responses, really. Unfortunately, it it still doesn't work. I tried what you both suggested, take a look at this console transcript: >> def aes(m,k,t) >> (aes = OpenSSL::Cipher::AES128.new("ECB").send(m)).key = k >> aes.update(t) << aes.final >> end => nil >> ?> def encrypt(key, text) >> aes(:encrypt, key, text) >> end => nil >> ?> def decrypt(key, text) >> aes(:decrypt, key, text) >> end => nil >> key = "82pjd12398JKBSDIGUSisahdoahOUASDHsdapdjqwjeASIduAsdh078asdASD087asdADSsdjhA7809asdajhADSs" => "82pjd12398JKBSDIGUSisahdoahOUASDHsdapdjqwjeASIduAsdh078asdASD087asdADSsdjhA7809asdajhADSs" >> u = User.find(1) => # >> u.password.length => 16 >> decrypt(key, u.password) OpenSSL::CipherError: bad decrypt from (irb):8:in `final' from (irb):8:in `aes' from (irb):16:in `decrypt' from (irb):19 >> decrypt(key, [u.password].pack("H*")) OpenSSL::CipherError: wrong final block length from (irb):8:in `final' from (irb):8:in `aes' from (irb):16:in `decrypt' from (irb):32 >> [u.password].pack("H*").length => 8 >> card = ([u.password].pack("H*") + ("\0" * 8)) => "9##n###\005\000\000\000\000\000\000\000\000" >> decrypt(key, card) OpenSSL::CipherError: bad decrypt from (irb):8:in `final' from (irb):8:in `aes' from (irb):16:in `decrypt' from (irb):43 Any other ideas? Thanks, -- Felipe -- Posted via http://www.ruby-forum.com/.