On this page
hmac.new
Prev: hmac.HMAC | Up: hmac
Rel: hmac.compare_digest, hmac.digest, hmac.HMAC
Ref: docs.python.org — hmac.new
Tags: #public #python3 #stdlib #hmac
Import
import hmac
from hmac import new
Signature & Overview
hmac.new(key, msg=None, digestmod='')
Create a new hashing object and return it.
Usage
import hashlib
import hmac
mac = hmac.new(b"signing-key", digestmod=hashlib.sha256)
mac.update(b"part1")
mac.update(b"part2")
assert mac.digest() == hmac.digest(b"signing-key", b"part1part2", "sha256")
Gotchas
digestmodis required: Always passhashlib.sha256(or"sha256") explicitly.
REPL Inspect
from hmac import new
help(new)
Linked from
Related notes
- tuts/python3/stdlib_module/hmac/compare_digest Linked here; links to this page; shared tags: #hmac, #stdlib
- tuts/python3/stdlib_module/hmac/digest Linked here; links to this page; shared tags: #hmac, #stdlib
- tuts/python3/stdlib_module/hmac/HMAC Linked here; links to this page; shared tags: #hmac, #stdlib
- tuts/python3/stdlib_module/hmac links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib