NAME

MD5 - Perl interface to the RSA Data Security Inc. MD5 Message-Digest Algorithm

SYNOPSIS

use MD5;

$context = new MD5;
$context->reset();

$context->add(LIST);
$context->addfile(HANDLE);

$digest = $context->digest();
$string = $context->hexdigest();

DESCRIPTION

The MD5 module allows you to use the RSA Data Security Inc. MD5 Message Digest algorithm from within Perl programs.

A new MD5 context object is created with the new operation. Multiple simultaneous digest contexts can be maintained, if desired. The context is updated with the add operation which adds the strings contained in the LIST parameter. The context is updated after each element is added so that add('foo', 'bar') may give different results to add('foobar').

The final message digest value is returned by the digest operation as a 16-byte binary string. This operation delivers the result of operations since the last new or reset operation. Once the operation has been performed, the context must be reset before being used to calculate another digest value.

Two convenience functions are also provided. The addfile operation takes an open file-handle and reads it until end-of file in 1024 byte blocks adding the contents to the context. The hexdigest operation calls digest and returns the result as a printable string of hexdecimal digits. This is exactly the same operation as performed by the unpack operation in the following example.

EXAMPLES

use MD5;

$md5 = new MD5;
$md5->add('foo', 'bar');
$md5->add('baz');
$digest = $md5->digest();

print("Digest is " . unpack("H*", $digest) . "\n");

The above exmaple would print out the message

Digest is 6df23dc03f9b54cc38a0fc1483df6e21

provided that the implementation is working correctly.

NOTE

The MD5 algorithm is defined in RFC1321. The basic C code is covered by the following copyright:

    Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved.

    License to copy and use this software is granted provided that it is identified as the "RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material mentioning or referencing this software or this function.

    License is also granted to make and use derivative works provided that such works are identified as "derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material mentioning or referencing the derived work.

    RSA Data Security, Inc. makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided "as is" without express or implied warranty of any kind.

    These notices must be retained in any copies of any part of this documentation and/or software.

AUTHOR

The MD5 interface was written by Neil Winton (N.Winton@axion.bt.co.uk).