Merged release21-maint changes.
[python/dscho.git] / Doc / lib / libmd5.tex
blob702b2bb54b5df3f36ec999ea204a202022ba1165
1 \section{\module{md5} ---
2 MD5 message digest algorithm}
4 \declaremodule{builtin}{md5}
5 \modulesynopsis{RSA's MD5 message digest algorithm.}
8 This module implements the interface to RSA's MD5 message digest
9 \index{message digest, MD5}
10 algorithm (see also Internet \rfc{1321}). Its use is quite
11 straightforward:\ use \function{new()} to create an md5 object.
12 You can now feed this object with arbitrary strings using the
13 \method{update()} method, and at any point you can ask it for the
14 \dfn{digest} (a strong kind of 128-bit checksum,
15 a.k.a. ``fingerprint'') of the concatenation of the strings fed to it
16 so far using the \method{digest()} method.
17 \index{checksum!MD5}
19 For example, to obtain the digest of the string \code{'Nobody inspects
20 the spammish repetition'}:
22 \begin{verbatim}
23 >>> import md5
24 >>> m = md5.new()
25 >>> m.update("Nobody inspects")
26 >>> m.update(" the spammish repetition")
27 >>> m.digest()
28 '\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9'
29 \end{verbatim}
31 More condensed:
33 \begin{verbatim}
34 >>> md5.new("Nobody inspects the spammish repetition").digest()
35 '\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9'
36 \end{verbatim}
38 \begin{funcdesc}{new}{\optional{arg}}
39 Return a new md5 object. If \var{arg} is present, the method call
40 \code{update(\var{arg})} is made.
41 \end{funcdesc}
43 \begin{funcdesc}{md5}{\optional{arg}}
44 For backward compatibility reasons, this is an alternative name for the
45 \function{new()} function.
46 \end{funcdesc}
48 An md5 object has the following methods:
50 \begin{methoddesc}[md5]{update}{arg}
51 Update the md5 object with the string \var{arg}. Repeated calls are
52 equivalent to a single call with the concatenation of all the
53 arguments: \code{m.update(a); m.update(b)} is equivalent to
54 \code{m.update(a+b)}.
55 \end{methoddesc}
57 \begin{methoddesc}[md5]{digest}{}
58 Return the digest of the strings passed to the \method{update()}
59 method so far. This is a 16-byte string which may contain
60 non-\ASCII{} characters, including null bytes.
61 \end{methoddesc}
63 \begin{methoddesc}[md5]{hexdigest}{}
64 Like \method{digest()} except the digest is returned as a string of
65 length 32, containing only hexadecimal digits. This may
66 be used to exchange the value safely in email or other non-binary
67 environments.
68 \end{methoddesc}
70 \begin{methoddesc}[md5]{copy}{}
71 Return a copy (``clone'') of the md5 object. This can be used to
72 efficiently compute the digests of strings that share a common initial
73 substring.
74 \end{methoddesc}
77 \begin{seealso}
78 \seemodule{sha}{Similar module implementing the Secure Hash
79 Algorithm (SHA). The SHA algorithm is considered a
80 more secure hash.}
81 \end{seealso}