MD5 function

S

sandhya mittal

--0-1706651872-1127594545=:57181
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Can anyone tell how to implement MD5 function(NOT algorithm) in Ruby.I ju=
st want to hex MD5 a string.It would be of great help.
=20
Thank You,
Sandhya

=09
 
1

1337p337

Can anyone tell how to implement MD5 function(NOT algorithm) in Ruby.I ju=
st want to hex MD5 a string.It would be of great help.

It's actually pretty easy:
=09require 'digest/md5'
=09Digest::MD5.new 'a random string.' # =3D> 8a6194e053d7a326fe301e902043be=
c1
This gets you a new Digest::MD5 object, which you'll usually .to_s. If all=
you
want is a string, you can do
=09Digest::MD5.hexdigest "Even randomer: #{rand}"
=09# =3D> "c69a37bb0328b781901665c671e1b367"
which just returns a string.

http://ruby-doc.org/stdlib/libdoc/digest/rdoc/index.html has more informati=
on.
 
D

Daniel Hobe

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')
=3D> "acbd18db4cc2f85cedef654fccc4a4d8"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,517
Latest member
Andres38A1

Latest Threads

Top