Tuesday, August 26, 2008

Perl: Generate MD5 Hash string

Share at Facebook

MD5 is one way hashing. process. For each data/string you'll always find a 32 length hex string, and always unique. Using Perl, below is the way to generate md5 string.

use strict;
use Digest::MD5 qw(md5_hex);
my $md5_data = "test";
my $md5_hash = md5_hex( $md5_data );
print "$md5_hash\n";

You'll get totally different for almost same string, though it is slightly different. For example your are doing md5 over "string md5 one 1" and "string md5 one 0". Just check difference is 0 and 1, but the md5 will be totally different and you can't guess any pattern. Check the example yourself using above example by changing the value of $md5_data.

MD5 is widely using for session tracking from web servers and many more processes. If you are interested to read more about md5 mechanism read from wiki http://en.wikipedia.org/wiki/MD5

If you are interested to more Perl with md5, then refer to this Perl module which I used at example http://search.cpan.org/~delta/Digest-Perl-MD5-1.6/lib/Digest/Perl/MD5.pm

For more Perl related article from my blog http://icfun.blogspot.com/search/label/perl


Ersalan said...

Thanks alot mate! Had been looking for something that actually made sense and CPAN wasn't it in this case unfortunately

HashHack said...

Be careful using MD5 - its very easily cracked online, you should take a look at my online md5 cracker if you dont believe me, but im making good money because people still use MD5, if you are using MD5 hashes, you need to be using salts to stop sites like mine from cracking it. Or better yet use something like SHA-386/SHA-512 hash and a salt.

Happy Hashing

Seo Newtool said...

An effective SEO tool that is useful in encoding passwords, credit card numbers and any other sensitive data in regard to.
md5 online generator