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 >
Text File  |  2000-03-23  |  8KB  |  213 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>MD5 - Perl interface to the RSA Data Security Inc. MD5 Message-Digest Algorithm</TITLE>
  5. <LINK REL="stylesheet" HREF="../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> MD5 - Perl interface to the RSA Data Security Inc. MD5 Message-Digest Algorithm</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#examples">EXAMPLES</A></LI>
  26.     <LI><A HREF="#note">NOTE</A></LI>
  27.     <LI><A HREF="#author">AUTHOR</A></LI>
  28.     <LI><A HREF="#see also">SEE ALSO</A></LI>
  29. </UL>
  30. <!-- INDEX END -->
  31.  
  32. <HR>
  33. <P>
  34. <H1><A NAME="name">NAME</A></H1>
  35. <P>MD5 - Perl interface to the RSA Data Security Inc. MD5 Message-Digest Algorithm</P>
  36. <P>
  37. <HR>
  38. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  39. <UL>
  40. <LI>Linux</LI>
  41. <LI>Solaris</LI>
  42. <LI>Windows</LI>
  43. </UL>
  44. <HR>
  45. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  46. <PRE>
  47.     use MD5;
  48. </PRE>
  49. <PRE>
  50.  
  51.     $context = new MD5;
  52.     $context->reset();</PRE>
  53. <PRE>
  54.  
  55.     $context->add(LIST);
  56.     $context->addfile(HANDLE);</PRE>
  57. <PRE>
  58.  
  59.     $digest = $context->digest();
  60.     $string = $context->hexdigest();</PRE>
  61. <PRE>
  62.     $digest = MD5->hash(SCALAR);
  63.     $string = MD5->hexhash(SCALAR);</PRE>
  64. <P>
  65. <HR>
  66. <H1><A NAME="description">DESCRIPTION</A></H1>
  67. <P>The <STRONG>MD5</STRONG> module allows you to use the RSA Data Security Inc. MD5
  68. Message Digest algorithm from within Perl programs.</P>
  69. <P>A new MD5 context object is created with the <STRONG>new</STRONG> operation.
  70. Multiple simultaneous digest contexts can be maintained, if desired.
  71. The context is updated with the <STRONG>add</STRONG> operation which adds the
  72. strings contained in the <EM>LIST</EM> parameter. Note, however, that
  73. <CODE>add('foo', 'bar')</CODE>, <CODE>add('foo')</CODE> followed by <CODE>add('bar')</CODE> and
  74. <CODE>add('foobar')</CODE> should all give the same result.</P>
  75. <P>The final message digest value is returned by the <STRONG>digest</STRONG> operation
  76. as a 16-byte binary string. This operation delivers the result of
  77. <STRONG>add</STRONG> operations since the last <STRONG>new</STRONG> or <STRONG>reset</STRONG> operation. Note
  78. that the <STRONG>digest</STRONG> operation is effectively a destructive, read-once
  79. operation. Once it has been performed, the context must be <STRONG>reset</STRONG>
  80. before being used to calculate another digest value.</P>
  81. <P>Several convenience functions are also provided. The <STRONG>addfile</STRONG>
  82. operation takes an open file-handle and reads it until end-of file in
  83. 1024 byte blocks adding the contents to the context. The file-handle
  84. can either be specified by name or passed as a type-glob reference, as
  85. shown in the examples below. The <STRONG>hexdigest</STRONG> operation calls
  86. <STRONG>digest</STRONG> and returns the result as a printable string of hexdecimal
  87. digits. This is exactly the same operation as performed by the
  88. <STRONG>unpack</STRONG> operation in the examples below.</P>
  89. <P>The <STRONG>hash</STRONG> operation can act as either a static member function (ie
  90. you invoke it on the MD5 class as in the synopsis above) or as a
  91. normal virtual function. In both cases it performs the complete MD5
  92. cycle (reset, add, digest) on the supplied scalar value. This is
  93. convenient for handling small quantities of data. When invoked on the
  94. class a temporary context is created. When invoked through an already
  95. created context object, this context is used. The latter form is
  96. slightly more efficient. The <STRONG>hexhash</STRONG> operation is analogous to
  97. <STRONG>hexdigest</STRONG>.</P>
  98. <P>
  99. <HR>
  100. <H1><A NAME="examples">EXAMPLES</A></H1>
  101. <PRE>
  102.     use MD5;
  103. </PRE>
  104. <PRE>
  105.  
  106.     $md5 = new MD5;
  107.     $md5->add('foo', 'bar');
  108.     $md5->add('baz');
  109.     $digest = $md5->digest();</PRE>
  110. <PRE>
  111.  
  112.     print("Digest is " . unpack("H*", $digest) . "\n");</PRE>
  113. <P>The above example would print out the message</P>
  114. <PRE>
  115.     Digest is 6df23dc03f9b54cc38a0fc1483df6e21</PRE>
  116. <P>provided that the implementation is working correctly.</P>
  117. <P>Remembering the Perl motto (``There's more than one way to do it''), the
  118. following should all give the same result:</P>
  119. <PRE>
  120.     use MD5;
  121.     $md5 = new MD5;</PRE>
  122. <PRE>
  123.     die "Can't open /etc/passwd ($!)\n" unless open(P, "/etc/passwd");</PRE>
  124. <PRE>
  125.     seek(P, 0, 0);
  126.     $md5->reset;
  127.     $md5->addfile(P);
  128.     $d = $md5->hexdigest;
  129.     print "addfile (handle name) = $d\n";</PRE>
  130. <PRE>
  131.     seek(P, 0, 0);
  132.     $md5->reset;
  133.     $md5->addfile(\*P);
  134.     $d = $md5->hexdigest;
  135.     print "addfile (type-glob reference) = $d\n";</PRE>
  136. <PRE>
  137.     seek(P, 0, 0);
  138.     $md5->reset;
  139.     while (<P>)
  140.     {
  141.         $md5->add($_);
  142.     }
  143.     $d = $md5->hexdigest;
  144.     print "Line at a time = $d\n";</PRE>
  145. <PRE>
  146.     seek(P, 0, 0);
  147.     $md5->reset;
  148.     $md5->add(<P>);
  149.     $d = $md5->hexdigest;
  150.     print "All lines at once = $d\n";</PRE>
  151. <PRE>
  152.     seek(P, 0, 0);
  153.     $md5->reset;
  154.     while (read(P, $data, (rand % 128) + 1))
  155.     {
  156.         $md5->add($data);
  157.     }
  158.     $d = $md5->hexdigest;
  159.     print "Random chunks = $d\n";</PRE>
  160. <PRE>
  161.     seek(P, 0, 0);
  162.     $md5->reset;
  163.     undef $/;
  164.     $data = <P>;
  165.     $d = $md5->hexhash($data);
  166.     print "Single string = $d\n";</PRE>
  167. <PRE>
  168.     close(P);</PRE>
  169. <P>
  170. <HR>
  171. <H1><A NAME="note">NOTE</A></H1>
  172. <P>The MD5 extension may be redistributed under the same terms as Perl.
  173. The MD5 algorithm is defined in RFC1321. The basic C code implementing
  174. the algorithm is derived from that in the RFC and is covered by the
  175. following copyright:</P>
  176. <P>Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
  177. rights reserved.</P>
  178. <P>License to copy and use this software is granted provided that it
  179. is identified as the ``RSA Data Security, Inc. MD5 Message-Digest
  180. Algorithm'' in all material mentioning or referencing this software
  181. or this function.</P>
  182. <P>License is also granted to make and use derivative works provided
  183. that such works are identified as ``derived from the RSA Data
  184. Security, Inc. MD5 Message-Digest Algorithm'' in all material
  185. mentioning or referencing the derived work.</P>
  186. <P>RSA Data Security, Inc. makes no representations concerning either
  187. the merchantability of this software or the suitability of this
  188. software for any particular purpose. It is provided ``as is''
  189. without express or implied warranty of any kind.</P>
  190. <P>These notices must be retained in any copies of any part of this
  191. documentation and/or software.</P>
  192. <P>This copyright does not prohibit distribution of any version of Perl
  193. containing this extension under the terms of the GNU or Artistic
  194. licences.</P>
  195. <P>
  196. <HR>
  197. <H1><A NAME="author">AUTHOR</A></H1>
  198. <P>The MD5 interface was written by Neil Winton
  199. (<CODE>N.Winton@axion.bt.co.uk</CODE>).</P>
  200. <P>
  201. <HR>
  202. <H1><A NAME="see also">SEE ALSO</A></H1>
  203. <P>perl(1).</P>
  204. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  205. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  206. <STRONG><P CLASS=block> MD5 - Perl interface to the RSA Data Security Inc. MD5 Message-Digest Algorithm</P></STRONG>
  207. </TD></TR>
  208. </TABLE>
  209.  
  210. </BODY>
  211.  
  212. </HTML>
  213.