Itโs not really an openssl solution at all, but it may work fine for you.
require 'mcrypt' require 'openssl' plaintext = 'password' puts plaintext key = '12345678901234567890123456789012' enc = Mcrypt.new(:rijndael_256, :ecb, key, nil, :zeros) encrypted = enc.encrypt(plaintext) puts Digest::MD5.hexdigest(encrypted)
I used an extra gem (ruby-mcrypt). There seems to be a problem with openssl. Actually, the problem is that Openssl does not support zero padding and uses either no-padding or default-openssl-padding. Due to the fact that you are using a zero padding in php, you should also use a zero padding in ruby.
Output on my computer for php script:
[~/test] โ php5 t.php 6337137fd88148250fd135a43dbeb84a
and for ruby โโscript:
[~/test] โ ruby t2.rb password 6337137fd88148250fd135a43dbeb84a
and my ruby โโversion:
[~/test] โ ruby -version ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
Hope this helps.
source share