home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / m / md5 < prev    next >
Text File  |  1996-11-14  |  3KB  |  57 lines

  1. <TITLE>md5 -- Python library reference</TITLE>
  2. Next: <A HREF="../m/mpz" TYPE="Next">mpz</A>  
  3. Prev: <A HREF="../c/cryptographic_services" TYPE="Prev">Cryptographic Services</A>  
  4. Up: <A HREF="../c/cryptographic_services" TYPE="Up">Cryptographic Services</A>  
  5. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  6. <H1>12.1. Built-in Module <CODE>md5</CODE></H1>
  7. This module implements the interface to RSA's MD5 message digest
  8. algorithm (see also Internet RFC 1321).  Its use is quite
  9. straightforward: use the <CODE>md5.new()</CODE> to create an md5 object.
  10. You can now feed this object with arbitrary strings using the
  11. <CODE>update()</CODE> method, and at any point you can ask it for the
  12. <DFN>digest</DFN> (a strong kind of 128-bit checksum,
  13. a.k.a. ``fingerprint'') of the contatenation of the strings fed to it
  14. so far using the <CODE>digest()</CODE> method.
  15. <P>
  16. For example, to obtain the digest of the string <CODE>"Nobody inspects
  17. the spammish repetition"</CODE>:
  18. <P>
  19. <UL COMPACT><CODE>>>> import md5<P>
  20. >>> m = md5.new()<P>
  21. >>> m.update("Nobody inspects")<P>
  22. >>> m.update(" the spammish repetition")<P>
  23. >>> m.digest()<P>
  24. '\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351'<P>
  25. </CODE></UL>
  26. More condensed:
  27. <P>
  28. <UL COMPACT><CODE>>>> md5.new("Nobody inspects the spammish repetition").digest()<P>
  29. '\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351'<P>
  30. </CODE></UL>
  31. <DL><DT><B>new</B> ([<VAR>arg</VAR>]) -- function of module md5<DD>
  32. Return a new md5 object.  If <VAR>arg</VAR> is present, the method call
  33. <CODE>update(<VAR>arg</VAR>)</CODE> is made.
  34. </DL>
  35. <DL><DT><B>md5</B> ([<VAR>arg</VAR>]) -- function of module md5<DD>
  36. For backward compatibility reasons, this is an alternative name for the
  37. <CODE>new()</CODE> function.
  38. </DL>
  39. An md5 object has the following methods:
  40. <P>
  41. <DL><DT><B>update</B> (<VAR>arg</VAR>) -- Method on md5<DD>
  42. Update the md5 object with the string <VAR>arg</VAR>.  Repeated calls are
  43. equivalent to a single call with the concatenation of all the
  44. arguments, i.e. <CODE>m.update(a); m.update(b)</CODE> is equivalent to
  45. <CODE>m.update(a+b)</CODE>.
  46. </DL>
  47. <DL><DT><B>digest</B> () -- Method on md5<DD>
  48. Return the digest of the strings passed to the <CODE>update()</CODE>
  49. method so far.  This is an 16-byte string which may contain
  50. non-ASCII characters, including null bytes.
  51. </DL>
  52. <DL><DT><B>copy</B> () -- Method on md5<DD>
  53. Return a copy (``clone'') of the md5 object.  This can be used to
  54. efficiently compute the digests of strings that share a common initial
  55. substring.
  56. </DL>
  57.