PATH:
usr
/
share
/
doc
/
python3-docs
/
html
/
_sources
/
library
:mod:`hmac` --- Keyed-Hashing for Message Authentication ======================================================== .. module:: hmac :synopsis: Keyed-Hashing for Message Authentication (HMAC) implementation .. moduleauthor:: Gerhard Häring <ghaering@users.sourceforge.net> .. sectionauthor:: Gerhard Häring <ghaering@users.sourceforge.net> **Source code:** :source:`Lib/hmac.py` -------------- This module implements the HMAC algorithm as described by :rfc:`2104`. .. function:: new(key, msg=None, digestmod=None) Return a new hmac object. *key* is a bytes or bytearray object giving the secret key. If *msg* is present, the method call ``update(msg)`` is made. *digestmod* is the digest name, digest constructor or module for the HMAC object to use. It supports any name suitable to :func:`hashlib.new` and defaults to the :data:`hashlib.md5` constructor. .. versionchanged:: 3.4 Parameter *key* can be a bytes or bytearray object. Parameter *msg* can be of any type supported by :mod:`hashlib`. Parameter *digestmod* can be the name of a hash algorithm. .. deprecated:: 3.4 MD5 as implicit default digest for *digestmod* is deprecated. An HMAC object has the following methods: .. method:: HMAC.update(msg) Update the hmac object with *msg*. Repeated calls are equivalent to a single call with the concatenation of all the arguments: ``m.update(a); m.update(b)`` is equivalent to ``m.update(a + b)``. .. versionchanged:: 3.4 Parameter *msg* can be of any type supported by :mod:`hashlib`. .. method:: HMAC.digest() Return the digest of the bytes passed to the :meth:`update` method so far. This bytes object will be the same length as the *digest_size* of the digest given to the constructor. It may contain non-ASCII bytes, including NUL bytes. .. warning:: When comparing the output of :meth:`digest` to an externally-supplied digest during a verification routine, it is recommended to use the :func:`compare_digest` function instead of the ``==`` operator to reduce the vulnerability to timing attacks. .. method:: HMAC.hexdigest() Like :meth:`digest` except the digest is returned as a string twice the length containing only hexadecimal digits. This may be used to exchange the value safely in email or other non-binary environments. .. warning:: When comparing the output of :meth:`hexdigest` to an externally-supplied digest during a verification routine, it is recommended to use the :func:`compare_digest` function instead of the ``==`` operator to reduce the vulnerability to timing attacks. .. method:: HMAC.copy() Return a copy ("clone") of the hmac object. This can be used to efficiently compute the digests of strings that share a common initial substring. A hash object has the following attributes: .. attribute:: HMAC.digest_size The size of the resulting HMAC digest in bytes. .. attribute:: HMAC.block_size The internal block size of the hash algorithm in bytes. .. versionadded:: 3.4 .. attribute:: HMAC.name The canonical name of this HMAC, always lowercase, e.g. ``hmac-md5``. .. versionadded:: 3.4 This module also provides the following helper function: .. function:: compare_digest(a, b) Return ``a == b``. This function uses an approach designed to prevent timing analysis by avoiding content-based short circuiting behaviour, making it appropriate for cryptography. *a* and *b* must both be of the same type: either :class:`str` (ASCII only, as e.g. returned by :meth:`HMAC.hexdigest`), or a :term:`bytes-like object`. .. note:: If *a* and *b* are of different lengths, or if an error occurs, a timing attack could theoretically reveal information about the types and lengths of *a* and *b*—but not their values. .. versionadded:: 3.3 .. seealso:: Module :mod:`hashlib` The Python module providing secure hash functions.
[+]
..
[-] crypt.rst.txt
[edit]
[-] logging.handlers.rst.txt
[edit]
[-] __main__.rst.txt
[edit]
[-] pty.rst.txt
[edit]
[-] email.rst.txt
[edit]
[-] traceback.rst.txt
[edit]
[-] fileinput.rst.txt
[edit]
[-] xml.sax.reader.rst.txt
[edit]
[-] curses.rst.txt
[edit]
[-] copy.rst.txt
[edit]
[-] aifc.rst.txt
[edit]
[-] xmlrpc.client.rst.txt
[edit]
[-] pydoc.rst.txt
[edit]
[-] asyncio-eventloops.rst.txt
[edit]
[-] uuid.rst.txt
[edit]
[-] functional.rst.txt
[edit]
[-] posix.rst.txt
[edit]
[-] hashlib.rst.txt
[edit]
[-] cmd.rst.txt
[edit]
[-] nntplib.rst.txt
[edit]
[-] python.rst.txt
[edit]
[-] types.rst.txt
[edit]
[-] exceptions.rst.txt
[edit]
[-] tracemalloc.rst.txt
[edit]
[-] othergui.rst.txt
[edit]
[-] xml.dom.pulldom.rst.txt
[edit]
[-] inspect.rst.txt
[edit]
[-] asyncio-stream.rst.txt
[edit]
[-] i18n.rst.txt
[edit]
[-] concurrent.rst.txt
[edit]
[-] imghdr.rst.txt
[edit]
[-] spwd.rst.txt
[edit]
[-] os.path.rst.txt
[edit]
[-] email.message.rst.txt
[edit]
[-] random.rst.txt
[edit]
[-] fileformats.rst.txt
[edit]
[-] faulthandler.rst.txt
[edit]
[-] parser.rst.txt
[edit]
[-] stat.rst.txt
[edit]
[-] code.rst.txt
[edit]
[-] email.headerregistry.rst.txt
[edit]
[-] timeit.rst.txt
[edit]
[-] optparse.rst.txt
[edit]
[-] smtplib.rst.txt
[edit]
[-] filesys.rst.txt
[edit]
[-] email.mime.rst.txt
[edit]
[-] itertools.rst.txt
[edit]
[-] sys.rst.txt
[edit]
[-] bdb.rst.txt
[edit]
[-] stringprep.rst.txt
[edit]
[-] asyncio-subprocess.rst.txt
[edit]
[-] decimal.rst.txt
[edit]
[-] unicodedata.rst.txt
[edit]
[-] intro.rst.txt
[edit]
[-] constants.rst.txt
[edit]
[-] xmlrpc.rst.txt
[edit]
[-] grp.rst.txt
[edit]
[-] pickle.rst.txt
[edit]
[-] mmap.rst.txt
[edit]
[-] debug.rst.txt
[edit]
[-] unittest.mock-examples.rst.txt
[edit]
[-] undoc.rst.txt
[edit]
[-] functools.rst.txt
[edit]
[-] ssl.rst.txt
[edit]
[-] locale.rst.txt
[edit]
[-] secrets.rst.txt
[edit]
[-] pprint.rst.txt
[edit]
[-] email.header.rst.txt
[edit]
[-] email.contentmanager.rst.txt
[edit]
[-] _thread.rst.txt
[edit]
[-] errno.rst.txt
[edit]
[-] sunau.rst.txt
[edit]
[-] syslog.rst.txt
[edit]
[-] tkinter.ttk.rst.txt
[edit]
[-] distribution.rst.txt
[edit]
[-] pdb.rst.txt
[edit]
[-] distutils.rst.txt
[edit]
[-] dummy_threading.rst.txt
[edit]
[-] text.rst.txt
[edit]
[-] socketserver.rst.txt
[edit]
[-] _dummy_thread.rst.txt
[edit]
[-] persistence.rst.txt
[edit]
[-] asyncio-eventloop.rst.txt
[edit]
[-] collections.abc.rst.txt
[edit]
[-] fnmatch.rst.txt
[edit]
[-] quopri.rst.txt
[edit]
[-] http.server.rst.txt
[edit]
[-] keyword.rst.txt
[edit]
[-] xml.dom.rst.txt
[edit]
[-] cgi.rst.txt
[edit]
[-] heapq.rst.txt
[edit]
[-] email.iterators.rst.txt
[edit]
[-] io.rst.txt
[edit]
[-] curses.panel.rst.txt
[edit]
[-] winreg.rst.txt
[edit]
[-] urllib.parse.rst.txt
[edit]
[-] unix.rst.txt
[edit]
[-] getpass.rst.txt
[edit]
[-] sched.rst.txt
[edit]
[-] socket.rst.txt
[edit]
[-] pipes.rst.txt
[edit]
[-] email.compat32-message.rst.txt
[edit]
[-] asyncio-sync.rst.txt
[edit]
[-] modulefinder.rst.txt
[edit]
[-] html.entities.rst.txt
[edit]
[-] ctypes.rst.txt
[edit]
[-] pyexpat.rst.txt
[edit]
[-] pyclbr.rst.txt
[edit]
[-] html.rst.txt
[edit]
[-] test.rst.txt
[edit]
[-] markup.rst.txt
[edit]
[-] doctest.rst.txt
[edit]
[-] csv.rst.txt
[edit]
[-] colorsys.rst.txt
[edit]
[-] xml.sax.rst.txt
[edit]
[-] zlib.rst.txt
[edit]
[-] subprocess.rst.txt
[edit]
[-] base64.rst.txt
[edit]
[-] platform.rst.txt
[edit]
[-] binascii.rst.txt
[edit]
[-] http.rst.txt
[edit]
[-] nis.rst.txt
[edit]
[-] statistics.rst.txt
[edit]
[-] sqlite3.rst.txt
[edit]
[-] json.rst.txt
[edit]
[-] gzip.rst.txt
[edit]
[-] netdata.rst.txt
[edit]
[-] pkgutil.rst.txt
[edit]
[-] linecache.rst.txt
[edit]
[-] cgitb.rst.txt
[edit]
[-] archiving.rst.txt
[edit]
[-] argparse.rst.txt
[edit]
[-] wsgiref.rst.txt
[edit]
[-] tokenize.rst.txt
[edit]
[-] mm.rst.txt
[edit]
[-] telnetlib.rst.txt
[edit]
[-] ossaudiodev.rst.txt
[edit]
[-] tk.rst.txt
[edit]
[-] string.rst.txt
[edit]
[-] misc.rst.txt
[edit]
[-] marshal.rst.txt
[edit]
[-] email.encoders.rst.txt
[edit]
[-] array.rst.txt
[edit]
[-] queue.rst.txt
[edit]
[-] copyreg.rst.txt
[edit]
[-] atexit.rst.txt
[edit]
[-] signal.rst.txt
[edit]
[-] collections.rst.txt
[edit]
[-] tkinter.scrolledtext.rst.txt
[edit]
[-] tempfile.rst.txt
[edit]
[-] codeop.rst.txt
[edit]
[-] threading.rst.txt
[edit]
[-] enum.rst.txt
[edit]
[-] imp.rst.txt
[edit]
[-] crypto.rst.txt
[edit]
[-] bisect.rst.txt
[edit]
[-] dbm.rst.txt
[edit]
[-] formatter.rst.txt
[edit]
[-] language.rst.txt
[edit]
[-] trace.rst.txt
[edit]
[-] tkinter.tix.rst.txt
[edit]
[-] smtpd.rst.txt
[edit]
[-] asyncio-task.rst.txt
[edit]
[-] abc.rst.txt
[edit]
[-] gettext.rst.txt
[edit]
[-] concurrency.rst.txt
[edit]
[-] allos.rst.txt
[edit]
[-] xml.sax.utils.rst.txt
[edit]
[-] tty.rst.txt
[edit]
[-] mailcap.rst.txt
[edit]
[-] msvcrt.rst.txt
[edit]
[-] reprlib.rst.txt
[edit]
[-] development.rst.txt
[edit]
[-] contextlib.rst.txt
[edit]
[-] configparser.rst.txt
[edit]
[-] symbol.rst.txt
[edit]
[-] shlex.rst.txt
[edit]
[-] tabnanny.rst.txt
[edit]
[-] asyncio-dev.rst.txt
[edit]
[-] py_compile.rst.txt
[edit]
[-] uu.rst.txt
[edit]
[-] logging.rst.txt
[edit]
[-] runpy.rst.txt
[edit]
[-] pathlib.rst.txt
[edit]
[-] os.rst.txt
[edit]
[-] urllib.request.rst.txt
[edit]
[-] html.parser.rst.txt
[edit]
[-] bz2.rst.txt
[edit]
[-] binhex.rst.txt
[edit]
[-] time.rst.txt
[edit]
[-] zipapp.rst.txt
[edit]
[-] fcntl.rst.txt
[edit]
[-] tkinter.rst.txt
[edit]
[-] glob.rst.txt
[edit]
[-] email.policy.rst.txt
[edit]
[-] pwd.rst.txt
[edit]
[-] numeric.rst.txt
[edit]
[-] winsound.rst.txt
[edit]
[-] urllib.robotparser.rst.txt
[edit]
[-] selectors.rst.txt
[edit]
[-] xdrlib.rst.txt
[edit]
[-] webbrowser.rst.txt
[edit]
[-] zipfile.rst.txt
[edit]
[-] ipc.rst.txt
[edit]
[-] mailbox.rst.txt
[edit]
[-] plistlib.rst.txt
[edit]
[-] getopt.rst.txt
[edit]
[-] concurrent.futures.rst.txt
[edit]
[-] symtable.rst.txt
[edit]
[-] rlcompleter.rst.txt
[edit]
[-] __future__.rst.txt
[edit]
[-] asynchat.rst.txt
[edit]
[-] audioop.rst.txt
[edit]
[-] compileall.rst.txt
[edit]
[-] unittest.mock.rst.txt
[edit]
[-] dis.rst.txt
[edit]
[-] index.rst.txt
[edit]
[-] logging.config.rst.txt
[edit]
[-] gc.rst.txt
[edit]
[-] shutil.rst.txt
[edit]
[-] sndhdr.rst.txt
[edit]
[-] ipaddress.rst.txt
[edit]
[-] asyncio-queue.rst.txt
[edit]
[-] curses.ascii.rst.txt
[edit]
[-] builtins.rst.txt
[edit]
[-] calendar.rst.txt
[edit]
[-] sysconfig.rst.txt
[edit]
[-] token.rst.txt
[edit]
[-] xml.dom.minidom.rst.txt
[edit]
[-] textwrap.rst.txt
[edit]
[-] importlib.rst.txt
[edit]
[-] fpectl.rst.txt
[edit]
[-] mimetypes.rst.txt
[edit]
[-] netrc.rst.txt
[edit]
[-] fractions.rst.txt
[edit]
[-] select.rst.txt
[edit]
[-] lzma.rst.txt
[edit]
[-] math.rst.txt
[edit]
[-] frameworks.rst.txt
[edit]
[-] ftplib.rst.txt
[edit]
[-] macpath.rst.txt
[edit]
[-] numbers.rst.txt
[edit]
[-] xml.etree.elementtree.rst.txt
[edit]
[-] pickletools.rst.txt
[edit]
[-] asyncore.rst.txt
[edit]
[-] warnings.rst.txt
[edit]
[-] resource.rst.txt
[edit]
[-] unittest.rst.txt
[edit]
[-] datetime.rst.txt
[edit]
[-] asyncio-protocol.rst.txt
[edit]
[-] urllib.rst.txt
[edit]
[-] superseded.rst.txt
[edit]
[-] email.generator.rst.txt
[edit]
[-] ensurepip.rst.txt
[edit]
[-] ast.rst.txt
[edit]
[-] modules.rst.txt
[edit]
[-] venv.rst.txt
[edit]
[-] internet.rst.txt
[edit]
[-] chunk.rst.txt
[edit]
[-] asyncio.rst.txt
[edit]
[-] turtle.rst.txt
[edit]
[-] struct.rst.txt
[edit]
[-] profile.rst.txt
[edit]
[-] urllib.error.rst.txt
[edit]
[-] http.cookiejar.rst.txt
[edit]
[-] tarfile.rst.txt
[edit]
[-] http.cookies.rst.txt
[edit]
[-] multiprocessing.rst.txt
[edit]
[-] msilib.rst.txt
[edit]
[-] xmlrpc.server.rst.txt
[edit]
[-] termios.rst.txt
[edit]
[-] 2to3.rst.txt
[edit]
[-] windows.rst.txt
[edit]
[-] email.examples.rst.txt
[edit]
[-] readline.rst.txt
[edit]
[-] binary.rst.txt
[edit]
[-] shelve.rst.txt
[edit]
[-] re.rst.txt
[edit]
[-] xml.sax.handler.rst.txt
[edit]
[-] hmac.rst.txt
[edit]
[-] datatypes.rst.txt
[edit]
[-] typing.rst.txt
[edit]
[-] custominterp.rst.txt
[edit]
[-] email.charset.rst.txt
[edit]
[-] email.util.rst.txt
[edit]
[-] zipimport.rst.txt
[edit]
[-] cmath.rst.txt
[edit]
[-] idle.rst.txt
[edit]
[-] operator.rst.txt
[edit]
[-] site.rst.txt
[edit]
[-] email.parser.rst.txt
[edit]
[-] functions.rst.txt
[edit]
[-] poplib.rst.txt
[edit]
[-] filecmp.rst.txt
[edit]
[-] codecs.rst.txt
[edit]
[-] imaplib.rst.txt
[edit]
[-] stdtypes.rst.txt
[edit]
[-] difflib.rst.txt
[edit]
[-] weakref.rst.txt
[edit]
[-] http.client.rst.txt
[edit]
[-] email.errors.rst.txt
[edit]
[-] xml.rst.txt
[edit]
[-] wave.rst.txt
[edit]