Can anyone tell how to implement MD5 function(NOT algorithm) in Ruby.I just want to hex MD5 a string.It would be of great help.
Thank You,
Sandhya
···
---------------------------------
Yahoo! for Good
Click here to donate to the Hurricane Katrina relief effort.
1337p337
(1337p337)
24 September 2005 20:58
2
It's actually pretty easy:
require 'digest/md5'
Digest::MD5.new 'a random string.' # => 8a6194e053d7a326fe301e902043bec1
This gets you a new Digest::MD5 object, which you'll usually .to_s. If all you
want is a string, you can do
Digest::MD5.hexdigest "Even randomer: #{rand}"
# => "c69a37bb0328b781901665c671e1b367"
which just returns a string.
http://ruby-doc.org/stdlib/libdoc/digest/rdoc/index.html has more information.
···
On 24/09/05, sandhya mittal <sandhya1205@yahoo.com> wrote:
Can anyone tell how to implement MD5 function(NOT algorithm) in Ruby.I just want to hex MD5 a string.It would be of great help.
require 'digest/md5'
Digest::MD5.hexdigest('foobar')
Don't use the digest/* modules. They're slower than the openssl ones
and have given me no end of trouble (mostly Segfaults):
require 'openssl'
OpenSSL::Digest::MD5.hexdigest('foo')
=> "acbd18db4cc2f85cedef654fccc4a4d8"
···
On 9/24/05, Kevin Ballard <kballard@gmail.com> wrote:
require 'digest/md5'
Digest::MD5.hexdigest('foobar')
Daniel Hobe <hobe@gmail.com> writes:
Don't use the digest/* modules. They're slower than the openssl ones
and have given me no end of trouble (mostly Segfaults):
require 'openssl'
OpenSSL::Digest::MD5.hexdigest('foo')
=> "acbd18db4cc2f85cedef654fccc4a4d8"
However, note that not everyone has OpenSSL installed (mostly due to
the lack of its headers when installing).
Digest::MD5 is more likely to be there, and I didn't have problems
with it so far.
In doubt, try and rescue.
···
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org