md5pass

This snippet is a simple wrapper around Digest::MD5‘s md5_base64() builds unsalted MD5 digests encoded in base64, very useful for LDAP management and LDIF file processing.

#!/usr/bin/perl
++$|;

use Digest::MD5 qw(md5_base64);

if(!defined($pass=shift)) {
        print "> ";
        $pass=<STDIN>;
        chomp $pass;
}
print encrypted($pass)."\n";

sub encrypted {
        my($passwd) = @_;
        return ‘{md5}’.md5_base64($passwd).‘==’;
}

(Source code)

Use it as such:

$ bin/md5pass
> password
{md5}X03MO1qnZdYdgyfeuILPmQ==

[tags]Perl, MD5, code, code snippet[/tags]

Posted in Code, General, Perl