On Friday, April 22, 2011 2:09:08 AM UTC-6, Ruby-Forum.com User wrote: > > $_SESSION["userpwd"] = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, > md5($cryptokey), $_POST['password'], MCRYPT_MODE_CBC, > md5(md5($cryptokey))));; > > Thanks. > I don't know if you just need help doing equivalent crypto operations in ruby, or if you need something that is binary-compatible with the above code (to have a ruby and php app. inter-operate for example).
If you just need equivalent crypto/encoding operations then I'd use OpenSSL (through the OpenSSL gem). MD5 hashing is available through Digest::MD5 (require 'digest/md5'). Base64 encoding/decoding can be done through the Base64 module. However, if you need to have the exact, binary-compatible ruby equivalent, then you need to be aware (if using OpenSSL) that mcrypt doesn't do PKCS-style padding (it just zero-pads if I remember correctly). This bit me when making a rails app. that had to read and write roundcube (a php app) session data and so if you're doing something similar, you'll want to be aware of the fact. You can tell OpenSSL to zero-pad if you need to: http://www.ruby-forum.com/topic/208273 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

