home *** CD-ROM | disk | FTP | other *** search
- <TITLE>md5 -- Python library reference</TITLE>
- Next: <A HREF="../m/mpz" TYPE="Next">mpz</A>
- Prev: <A HREF="../c/cryptographic_services" TYPE="Prev">Cryptographic Services</A>
- Up: <A HREF="../c/cryptographic_services" TYPE="Up">Cryptographic Services</A>
- Top: <A HREF="../t/top" TYPE="Top">Top</A>
- <H1>12.1. Built-in Module <CODE>md5</CODE></H1>
- This module implements the interface to RSA's MD5 message digest
- algorithm (see also Internet RFC 1321). Its use is quite
- straightforward: use the <CODE>md5.new()</CODE> to create an md5 object.
- You can now feed this object with arbitrary strings using the
- <CODE>update()</CODE> method, and at any point you can ask it for the
- <DFN>digest</DFN> (a strong kind of 128-bit checksum,
- a.k.a. ``fingerprint'') of the contatenation of the strings fed to it
- so far using the <CODE>digest()</CODE> method.
- <P>
- For example, to obtain the digest of the string <CODE>"Nobody inspects
- the spammish repetition"</CODE>:
- <P>
- <UL COMPACT><CODE>>>> import md5<P>
- >>> m = md5.new()<P>
- >>> m.update("Nobody inspects")<P>
- >>> m.update(" the spammish repetition")<P>
- >>> m.digest()<P>
- '\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351'<P>
- </CODE></UL>
- More condensed:
- <P>
- <UL COMPACT><CODE>>>> md5.new("Nobody inspects the spammish repetition").digest()<P>
- '\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351'<P>
- </CODE></UL>
- <DL><DT><B>new</B> ([<VAR>arg</VAR>]) -- function of module md5<DD>
- Return a new md5 object. If <VAR>arg</VAR> is present, the method call
- <CODE>update(<VAR>arg</VAR>)</CODE> is made.
- </DL>
- <DL><DT><B>md5</B> ([<VAR>arg</VAR>]) -- function of module md5<DD>
- For backward compatibility reasons, this is an alternative name for the
- <CODE>new()</CODE> function.
- </DL>
- An md5 object has the following methods:
- <P>
- <DL><DT><B>update</B> (<VAR>arg</VAR>) -- Method on md5<DD>
- Update the md5 object with the string <VAR>arg</VAR>. Repeated calls are
- equivalent to a single call with the concatenation of all the
- arguments, i.e. <CODE>m.update(a); m.update(b)</CODE> is equivalent to
- <CODE>m.update(a+b)</CODE>.
- </DL>
- <DL><DT><B>digest</B> () -- Method on md5<DD>
- Return the digest of the strings passed to the <CODE>update()</CODE>
- method so far. This is an 16-byte string which may contain
- non-ASCII characters, including null bytes.
- </DL>
- <DL><DT><B>copy</B> () -- Method on md5<DD>
- Return a copy (``clone'') of the md5 object. This can be used to
- efficiently compute the digests of strings that share a common initial
- substring.
- </DL>
-