From: Brian Candler Date: 2008-12-15T20:57:52+09:00 Subject: Re: Ruby encryption Archana Thota wrote: > Output of php encryption code and output of rails encryption code are > not same. Presumably they're not doing the same things. In particular, I see that you're doing an SHA1 on the key in the Ruby code, but not the php. Try inserting debugging to look at intermediate values, e.g. puts "key = #{key.inspect}" (and whatever the PHP equivalent is in the PHP code) Also, I have no idea what you're doing with all that SHA1 unpacking, mapping and packing. It seems that the final result is the same as a simple Digest::SHA1.digest, but with 12 extra zeros on the end. irb(main):001:0> password = "foobar" => "foobar" irb(main):002:0> require 'digest/sha1' => true irb(main):003:0> Digest::SHA1.hexdigest(password).unpack('a2'*32).map{|x| x.hex}.pack('c'*32) => "\210C\327\371$\026!\035\351\353\271c\377L\342\201%\223(x\000\000\000\000\000\000\000\000\000\000\000\000" irb(main):004:0> Digest::SHA1.digest(password) => "\210C\327\371$\026!\035\351\353\271c\377L\342\201%\223(x" -- Posted via http://www.ruby-forum.com/.