On this page
hmac.compare_digest
Up: hmac | Next: hmac.digest
Rel: hmac.digest, hmac.HMAC, hmac.new
Ref: docs.python.org — hmac.compare_digest
Tags: #public #python3 #stdlib #hmac
Import
import hmac
from hmac import compare_digest
Signature & Overview
hmac.compare_digest(a, b, /)
Return 'a == b'.
Usage
import hmac
assert hmac.compare_digest(b"abc", b"abc") is True
assert hmac.compare_digest(b"abc", b"abd") is False
Gotchas
- Always use
compare_digest()when verifying MACs/webhooks: Prevents timing attacks.
REPL Inspect
from hmac import compare_digest
help(compare_digest)
Linked from
Related notes
- 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/new 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