blob: 3e228201a077fcc53378cf5920daf42348b31355 [file] [log] [blame]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001\section{Built-in module \sectcode{md5}}
2\bimodindex{md5}
3
4This module implements the interface to RSA's MD5 message digest
Guido van Rossum16d6e711994-08-08 12:30:22 +00005algorithm (see also the file \file{md5.doc}). Its use is quite
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00006straightforward: use the function \code{md5} to create an
7\dfn{md5}-object. You can now ``feed'' this object with arbitrary
8strings.
9
Guido van Rossum16d6e711994-08-08 12:30:22 +000010At any time you can ask for the ``final'' digest of the object. Internally,
11a temporary copy of the object is made and the digest is computed and
12returned. Because of the copy, the digest operation is not destructive
13for the object. Before a more exact description of the module's use, a small
14example will be helpful:
15to obtain the digest of the string \code{'abc'}, use \ldots
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000016
17\bcode\begin{verbatim}
Guido van Rossum31cce971995-01-04 19:17:34 +000018>>> import md5
19>>> m = md5.new()
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000020>>> m.update('abc')
21>>> m.digest()
22'\220\001P\230<\322O\260\326\226?}(\341\177r'
23\end{verbatim}\ecode
24
25More condensed:
26
27\bcode\begin{verbatim}
Guido van Rossum31cce971995-01-04 19:17:34 +000028>>> md5.new('abc').digest()
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000029'\220\001P\230<\322O\260\326\226?}(\341\177r'
30\end{verbatim}\ecode
31
32\renewcommand{\indexsubitem}{(in module md5)}
Guido van Rossum31cce971995-01-04 19:17:34 +000033
34\begin{funcdesc}{new}{\optional{arg}}
Guido van Rossum16d6e711994-08-08 12:30:22 +000035 Create a new md5-object. If \var{arg} is present, an initial
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000036 \code{update} method is called with \var{arg} as argument.
37\end{funcdesc}
38
Guido van Rossum31cce971995-01-04 19:17:34 +000039\begin{funcdesc}{md5}{\optional{arg}}
40For backward compatibility reasons, this is an alternative name for the
41\code{new} function.
42\end{funcdesc}
43
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000044An md5-object has the following methods:
45
46\renewcommand{\indexsubitem}{(md5 method)}
47\begin{funcdesc}{update}{arg}
48 Update this md5-object with the string \var{arg}.
49\end{funcdesc}
50
51\begin{funcdesc}{digest}{}
Guido van Rossum16d6e711994-08-08 12:30:22 +000052% XXX The following is not quite clear; what does MD5Final do?
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000053 Return the \dfn{digest} of this md5-object. Internally, a copy is made
54 and the \C-function \code{MD5Final} is called. Finally the digest is
55 returned.
56\end{funcdesc}
57
58\begin{funcdesc}{copy}{}
59 Return a separate copy of this md5-object. An \code{update} to this
60 copy won't affect the original object.
61\end{funcdesc}