/Doc/library/hmac.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 61 lines · 34 code · 27 blank · 0 comment · 0 complexity · 7bd4c502cc0374692812089b95a6fa23 MD5 · raw file

  1. :mod:`hmac` --- Keyed-Hashing for Message Authentication
  2. ========================================================
  3. .. module:: hmac
  4. :synopsis: Keyed-Hashing for Message Authentication (HMAC) implementation for Python.
  5. .. moduleauthor:: Gerhard H채ring <ghaering@users.sourceforge.net>
  6. .. sectionauthor:: Gerhard H채ring <ghaering@users.sourceforge.net>
  7. .. versionadded:: 2.2
  8. This module implements the HMAC algorithm as described by :rfc:`2104`.
  9. .. function:: new(key[, msg[, digestmod]])
  10. Return a new hmac object. If *msg* is present, the method call ``update(msg)``
  11. is made. *digestmod* is the digest constructor or module for the HMAC object to
  12. use. It defaults to the :func:`hashlib.md5` constructor.
  13. .. note::
  14. The md5 hash has known weaknesses but remains the default for backwards
  15. compatibility. Choose a better one for your application.
  16. An HMAC object has the following methods:
  17. .. method:: hmac.update(msg)
  18. Update the hmac object with the string *msg*. Repeated calls are equivalent to
  19. a single call with the concatenation of all the arguments: ``m.update(a);
  20. m.update(b)`` is equivalent to ``m.update(a + b)``.
  21. .. method:: hmac.digest()
  22. Return the digest of the strings passed to the :meth:`update` method so far.
  23. This string will be the same length as the *digest_size* of the digest given to
  24. the constructor. It may contain non-ASCII characters, including NUL bytes.
  25. .. method:: hmac.hexdigest()
  26. Like :meth:`digest` except the digest is returned as a string twice the length
  27. containing only hexadecimal digits. This may be used to exchange the value
  28. safely in email or other non-binary environments.
  29. .. method:: hmac.copy()
  30. Return a copy ("clone") of the hmac object. This can be used to efficiently
  31. compute the digests of strings that share a common initial substring.
  32. .. seealso::
  33. Module :mod:`hashlib`
  34. The python module providing secure hash functions.