source: vendor/python/2.5/Doc/lib/libmd5.tex

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 3.0 KB
Line 
1\section{\module{md5} ---
2 MD5 message digest algorithm}
3
4\declaremodule{builtin}{md5}
5\modulesynopsis{RSA's MD5 message digest algorithm.}
6
7\deprecated{2.5}{Use the \refmodule{hashlib} module instead.}
8
9This module implements the interface to RSA's MD5 message digest
10\index{message digest, MD5}
11algorithm (see also Internet \rfc{1321}). Its use is quite
12straightforward:\ use \function{new()} to create an md5 object.
13You can now feed this object with arbitrary strings using the
14\method{update()} method, and at any point you can ask it for the
15\dfn{digest} (a strong kind of 128-bit checksum,
16a.k.a. ``fingerprint'') of the concatenation of the strings fed to it
17so far using the \method{digest()} method.
18\index{checksum!MD5}
19
20For example, to obtain the digest of the string \code{'Nobody inspects
21the spammish repetition'}:
22
23\begin{verbatim}
24>>> import md5
25>>> m = md5.new()
26>>> m.update("Nobody inspects")
27>>> m.update(" the spammish repetition")
28>>> m.digest()
29'\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9'
30\end{verbatim}
31
32More condensed:
33
34\begin{verbatim}
35>>> md5.new("Nobody inspects the spammish repetition").digest()
36'\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9'
37\end{verbatim}
38
39The following values are provided as constants in the module and as
40attributes of the md5 objects returned by \function{new()}:
41
42\begin{datadesc}{digest_size}
43 The size of the resulting digest in bytes. This is always
44 \code{16}.
45\end{datadesc}
46
47The md5 module provides the following functions:
48
49\begin{funcdesc}{new}{\optional{arg}}
50Return a new md5 object. If \var{arg} is present, the method call
51\code{update(\var{arg})} is made.
52\end{funcdesc}
53
54\begin{funcdesc}{md5}{\optional{arg}}
55For backward compatibility reasons, this is an alternative name for the
56\function{new()} function.
57\end{funcdesc}
58
59An md5 object has the following methods:
60
61\begin{methoddesc}[md5]{update}{arg}
62Update the md5 object with the string \var{arg}. Repeated calls are
63equivalent to a single call with the concatenation of all the
64arguments: \code{m.update(a); m.update(b)} is equivalent to
65\code{m.update(a+b)}.
66\end{methoddesc}
67
68\begin{methoddesc}[md5]{digest}{}
69Return the digest of the strings passed to the \method{update()}
70method so far. This is a 16-byte string which may contain
71non-\ASCII{} characters, including null bytes.
72\end{methoddesc}
73
74\begin{methoddesc}[md5]{hexdigest}{}
75Like \method{digest()} except the digest is returned as a string of
76length 32, containing only hexadecimal digits. This may
77be used to exchange the value safely in email or other non-binary
78environments.
79\end{methoddesc}
80
81\begin{methoddesc}[md5]{copy}{}
82Return a copy (``clone'') of the md5 object. This can be used to
83efficiently compute the digests of strings that share a common initial
84substring.
85\end{methoddesc}
86
87
88\begin{seealso}
89 \seemodule{sha}{Similar module implementing the Secure Hash
90 Algorithm (SHA). The SHA algorithm is considered a
91 more secure hash.}
92\end{seealso}
Note: See TracBrowser for help on using the repository browser.