📄 module-md5.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>15.1 md5 -- MD5 message digest algorithm</title>
<META NAME="description" CONTENT="15.1 md5 -- MD5 message digest algorithm">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-sha.html" tppabs="http://www.python.org/doc/current/lib/module-sha.html">
<LINK REL="previous" href="crypto.html" tppabs="http://www.python.org/doc/current/lib/crypto.html">
<LINK REL="up" href="crypto.html" tppabs="http://www.python.org/doc/current/lib/crypto.html">
<LINK REL="next" href="module-sha.html" tppabs="http://www.python.org/doc/current/lib/module-sha.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="crypto.html" tppabs="http://www.python.org/doc/current/lib/crypto.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="crypto.html" tppabs="http://www.python.org/doc/current/lib/crypto.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-sha.html" tppabs="http://www.python.org/doc/current/lib/module-sha.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="crypto.html" tppabs="http://www.python.org/doc/current/lib/crypto.html">15. Cryptographic Services</A>
<b class="navlabel">Up:</b> <a class="sectref" href="crypto.html" tppabs="http://www.python.org/doc/current/lib/crypto.html">15. Cryptographic Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-sha.html" tppabs="http://www.python.org/doc/current/lib/module-sha.html">15.2 sha </A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0017100000000000000000">
15.1 <tt class="module">md5</tt> --
MD5 message digest algorithm</A>
</H1>
<P>
<P>
This module implements the interface to RSA's MD5 message digest
algorithm (see also Internet <a class="rfc" name="rfcref-48140"
href="javascript:if(confirm('http://www.ietf.org/rfc/rfc1321.txt \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.ietf.org/rfc/rfc1321.txt'" tppabs="http://www.ietf.org/rfc/rfc1321.txt">RFC 1321 <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
></a>). Its use is quite
straightforward: use <tt class="function">new()</tt> to create an md5 object.
You can now feed this object with arbitrary strings using the
<tt class="method">update()</tt> method, and at any point you can ask it for the
<i class="dfn">digest</i> (a strong kind of 128-bit checksum,
a.k.a. ``fingerprint'') of the concatenation of the strings fed to it
so far using the <tt class="method">digest()</tt> method.
<P>
For example, to obtain the digest of the string <code>'Nobody inspects
the spammish repetition'</code>:
<P>
<dl><dd><pre class="verbatim">
>>> import md5
>>> m = md5.new()
>>> m.update("Nobody inspects")
>>> m.update(" the spammish repetition")
>>> m.digest()
'\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351'
</pre></dl>
<P>
More condensed:
<P>
<dl><dd><pre class="verbatim">
>>> md5.new("Nobody inspects the spammish repetition").digest()
'\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351'
</pre></dl>
<P>
<dl><dt><b><a name='l2h-2943'><tt class='function'>new</tt></a></b> (<big>[</big><var>arg</var><big>]</big>)
<dd>
Return a new md5 object. If <var>arg</var> is present, the method call
<code>update(<var>arg</var>)</code> is made.
</dl>
<P>
<dl><dt><b><a name='l2h-2944'><tt class='function'>md5</tt></a></b> (<big>[</big><var>arg</var><big>]</big>)
<dd>
For backward compatibility reasons, this is an alternative name for the
<tt class="function">new()</tt> function.
</dl>
<P>
An md5 object has the following methods:
<P>
<dl><dt><b><a name='l2h-2945'><tt class='method'>update</tt></a></b> (<var>arg</var>)
<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>
<P>
<dl><dt><b><a name='l2h-2946'><tt class='method'>digest</tt></a></b> ()
<dd>
Return the digest of the strings passed to the <tt class="method">update()</tt>
method so far. This is a 16-byte string which may contain
non-ASCII characters, including null bytes.
</dl>
<P>
<dl><dt><b><a name='l2h-2947'><tt class='method'>hexdigest</tt></a></b> ()
<dd>
Like <tt class="method">digest()</tt> except the digest is returned as a string of
length 32, containing only hexadecimal digits. This may
be used to exchange the value safely in email or other non-binary
environments.
</dl>
<P>
<dl><dt><b><a name='l2h-2948'><tt class='method'>copy</tt></a></b> ()
<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>
<P>
<div class='seealso'>
<p class='heading'><b>See Also:</b></p>
<dl compact class="seemodule">
<dt>Module <b><tt class='module'><a href="module-sha.html" tppabs="http://www.python.org/doc/current/lib/module-sha.html">sha</a></tt>:</b>
<dd>Similar module implementing the Secure Hash
Algorithm (SHA). The SHA algorithm is considered a
more secure hash.
</dl>
</div>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="crypto.html" tppabs="http://www.python.org/doc/current/lib/crypto.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="crypto.html" tppabs="http://www.python.org/doc/current/lib/crypto.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-sha.html" tppabs="http://www.python.org/doc/current/lib/module-sha.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="crypto.html" tppabs="http://www.python.org/doc/current/lib/crypto.html">15. Cryptographic Services</A>
<b class="navlabel">Up:</b> <a class="sectref" href="crypto.html" tppabs="http://www.python.org/doc/current/lib/crypto.html">15. Cryptographic Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-sha.html" tppabs="http://www.python.org/doc/current/lib/module-sha.html">15.2 sha </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -