May, 2014

...now browsing by month

 

MD5 hash using Perl

Monday, May 12th, 2014

Earlier, I demonstrated using groovy with a simple bit of code to create an MD5 hash. Here is a Perl version, notice how little code is used.

#!/usr/bin/perl
use strict;
use warnings;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use Digest::SHA qw(sha1 sha1_hex sha1_base64);
use MIME::Base64;
my $password;
if (scalar @ARGV eq 1) {
	$password = shift;
} else {
	$password = "password";
}
print "MD5 hex digest of $password = ",md5_hex($password), "\n";  # human-readable
print "MD5 base64 digest of $password = ",md5_base64($password), "\n";  # human-readable too
print "SHA1 hex digest of $password = ",sha1_hex($password), "\n";  # human-readable
print "SHA1 base64 digest of $password = ",sha1_base64($password), "\n";  # human-readable too

Pretty cool, and this code runs on just about any linux/unix machine. In Windows, I ran the code using Strawberry Perl.