home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_0ad8d53b44fa8ce5592874474978a8c3
< prev
next >
Wrap
Text File
|
2000-03-23
|
8KB
|
213 lines
<HTML>
<HEAD>
<TITLE>MD5 - Perl interface to the RSA Data Security Inc. MD5 Message-Digest Algorithm</TITLE>
<LINK REL="stylesheet" HREF="../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> MD5 - Perl interface to the RSA Data Security Inc. MD5 Message-Digest Algorithm</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
<LI><A HREF="#examples">EXAMPLES</A></LI>
<LI><A HREF="#note">NOTE</A></LI>
<LI><A HREF="#author">AUTHOR</A></LI>
<LI><A HREF="#see also">SEE ALSO</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>MD5 - Perl interface to the RSA Data Security Inc. MD5 Message-Digest Algorithm</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
use MD5;
</PRE>
<PRE>
$context = new MD5;
$context->reset();</PRE>
<PRE>
$context->add(LIST);
$context->addfile(HANDLE);</PRE>
<PRE>
$digest = $context->digest();
$string = $context->hexdigest();</PRE>
<PRE>
$digest = MD5->hash(SCALAR);
$string = MD5->hexhash(SCALAR);</PRE>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>The <STRONG>MD5</STRONG> module allows you to use the RSA Data Security Inc. MD5
Message Digest algorithm from within Perl programs.</P>
<P>A new MD5 context object is created with the <STRONG>new</STRONG> operation.
Multiple simultaneous digest contexts can be maintained, if desired.
The context is updated with the <STRONG>add</STRONG> operation which adds the
strings contained in the <EM>LIST</EM> parameter. Note, however, that
<CODE>add('foo', 'bar')</CODE>, <CODE>add('foo')</CODE> followed by <CODE>add('bar')</CODE> and
<CODE>add('foobar')</CODE> should all give the same result.</P>
<P>The final message digest value is returned by the <STRONG>digest</STRONG> operation
as a 16-byte binary string. This operation delivers the result of
<STRONG>add</STRONG> operations since the last <STRONG>new</STRONG> or <STRONG>reset</STRONG> operation. Note
that the <STRONG>digest</STRONG> operation is effectively a destructive, read-once
operation. Once it has been performed, the context must be <STRONG>reset</STRONG>
before being used to calculate another digest value.</P>
<P>Several convenience functions are also provided. The <STRONG>addfile</STRONG>
operation takes an open file-handle and reads it until end-of file in
1024 byte blocks adding the contents to the context. The file-handle
can either be specified by name or passed as a type-glob reference, as
shown in the examples below. The <STRONG>hexdigest</STRONG> operation calls
<STRONG>digest</STRONG> and returns the result as a printable string of hexdecimal
digits. This is exactly the same operation as performed by the
<STRONG>unpack</STRONG> operation in the examples below.</P>
<P>The <STRONG>hash</STRONG> operation can act as either a static member function (ie
you invoke it on the MD5 class as in the synopsis above) or as a
normal virtual function. In both cases it performs the complete MD5
cycle (reset, add, digest) on the supplied scalar value. This is
convenient for handling small quantities of data. When invoked on the
class a temporary context is created. When invoked through an already
created context object, this context is used. The latter form is
slightly more efficient. The <STRONG>hexhash</STRONG> operation is analogous to
<STRONG>hexdigest</STRONG>.</P>
<P>
<HR>
<H1><A NAME="examples">EXAMPLES</A></H1>
<PRE>
use MD5;
</PRE>
<PRE>
$md5 = new MD5;
$md5->add('foo', 'bar');
$md5->add('baz');
$digest = $md5->digest();</PRE>
<PRE>
print("Digest is " . unpack("H*", $digest) . "\n");</PRE>
<P>The above example would print out the message</P>
<PRE>
Digest is 6df23dc03f9b54cc38a0fc1483df6e21</PRE>
<P>provided that the implementation is working correctly.</P>
<P>Remembering the Perl motto (``There's more than one way to do it''), the
following should all give the same result:</P>
<PRE>
use MD5;
$md5 = new MD5;</PRE>
<PRE>
die "Can't open /etc/passwd ($!)\n" unless open(P, "/etc/passwd");</PRE>
<PRE>
seek(P, 0, 0);
$md5->reset;
$md5->addfile(P);
$d = $md5->hexdigest;
print "addfile (handle name) = $d\n";</PRE>
<PRE>
seek(P, 0, 0);
$md5->reset;
$md5->addfile(\*P);
$d = $md5->hexdigest;
print "addfile (type-glob reference) = $d\n";</PRE>
<PRE>
seek(P, 0, 0);
$md5->reset;
while (<P>)
{
$md5->add($_);
}
$d = $md5->hexdigest;
print "Line at a time = $d\n";</PRE>
<PRE>
seek(P, 0, 0);
$md5->reset;
$md5->add(<P>);
$d = $md5->hexdigest;
print "All lines at once = $d\n";</PRE>
<PRE>
seek(P, 0, 0);
$md5->reset;
while (read(P, $data, (rand % 128) + 1))
{
$md5->add($data);
}
$d = $md5->hexdigest;
print "Random chunks = $d\n";</PRE>
<PRE>
seek(P, 0, 0);
$md5->reset;
undef $/;
$data = <P>;
$d = $md5->hexhash($data);
print "Single string = $d\n";</PRE>
<PRE>
close(P);</PRE>
<P>
<HR>
<H1><A NAME="note">NOTE</A></H1>
<P>The MD5 extension may be redistributed under the same terms as Perl.
The MD5 algorithm is defined in RFC1321. The basic C code implementing
the algorithm is derived from that in the RFC and is covered by the
following copyright:</P>
<P>Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.</P>
<P>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.</P>
<P>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.</P>
<P>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.</P>
<P>These notices must be retained in any copies of any part of this
documentation and/or software.</P>
<P>This copyright does not prohibit distribution of any version of Perl
containing this extension under the terms of the GNU or Artistic
licences.</P>
<P>
<HR>
<H1><A NAME="author">AUTHOR</A></H1>
<P>The MD5 interface was written by Neil Winton
(<CODE>N.Winton@axion.bt.co.uk</CODE>).</P>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P>perl(1).</P>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> MD5 - Perl interface to the RSA Data Security Inc. MD5 Message-Digest Algorithm</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>