blob: edaa7272485af863e7681c3c25424096eb0851fe [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}
18>>> from md5 import md5
19>>> m = md5()
20>>> 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}
28>>> md5('abc').digest()
29'\220\001P\230<\322O\260\326\226?}(\341\177r'
30\end{verbatim}\ecode
31
32\renewcommand{\indexsubitem}{(in module md5)}
Guido van Rossum16d6e711994-08-08 12:30:22 +000033\begin{funcdesc}{md5}{\optional{arg}}
34 Create a new md5-object. If \var{arg} is present, an initial
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000035 \code{update} method is called with \var{arg} as argument.
36\end{funcdesc}
37
38An md5-object has the following methods:
39
40\renewcommand{\indexsubitem}{(md5 method)}
41\begin{funcdesc}{update}{arg}
42 Update this md5-object with the string \var{arg}.
43\end{funcdesc}
44
45\begin{funcdesc}{digest}{}
Guido van Rossum16d6e711994-08-08 12:30:22 +000046% XXX The following is not quite clear; what does MD5Final do?
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000047 Return the \dfn{digest} of this md5-object. Internally, a copy is made
48 and the \C-function \code{MD5Final} is called. Finally the digest is
49 returned.
50\end{funcdesc}
51
52\begin{funcdesc}{copy}{}
53 Return a separate copy of this md5-object. An \code{update} to this
54 copy won't affect the original object.
55\end{funcdesc}