blob: 480d0a7b4896ef0aa2eda719f6127f05b6a06030 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001
2:mod:`hmac` --- Keyed-Hashing for Message Authentication
3========================================================
4
5.. module:: hmac
6 :synopsis: Keyed-Hashing for Message Authentication (HMAC) implementation for Python.
7.. moduleauthor:: Gerhard Häring <ghaering@users.sourceforge.net>
8.. sectionauthor:: Gerhard Häring <ghaering@users.sourceforge.net>
9
10
11.. versionadded:: 2.2
12
13This module implements the HMAC algorithm as described by :rfc:`2104`.
14
15
16.. function:: new(key[, msg[, digestmod]])
17
18 Return a new hmac object. If *msg* is present, the method call ``update(msg)``
19 is made. *digestmod* is the digest constructor or module for the HMAC object to
20 use. It defaults to the :func:`hashlib.md5` constructor.
21
Georg Brandl8ec7f652007-08-15 14:28:01 +000022
23An HMAC object has the following methods:
24
25
26.. method:: hmac.update(msg)
27
28 Update the hmac object with the string *msg*. Repeated calls are equivalent to
29 a single call with the concatenation of all the arguments: ``m.update(a);
30 m.update(b)`` is equivalent to ``m.update(a + b)``.
31
32
33.. method:: hmac.digest()
34
35 Return the digest of the strings passed to the :meth:`update` method so far.
36 This string will be the same length as the *digest_size* of the digest given to
37 the constructor. It may contain non-ASCII characters, including NUL bytes.
38
39
40.. method:: hmac.hexdigest()
41
42 Like :meth:`digest` except the digest is returned as a string twice the length
43 containing only hexadecimal digits. This may be used to exchange the value
44 safely in email or other non-binary environments.
45
46
47.. method:: hmac.copy()
48
49 Return a copy ("clone") of the hmac object. This can be used to efficiently
50 compute the digests of strings that share a common initial substring.
51
52
53.. seealso::
54
55 Module :mod:`hashlib`
Ezio Melotti062d2b52009-12-19 22:41:49 +000056 The Python module providing secure hash functions.
Georg Brandl8ec7f652007-08-15 14:28:01 +000057