hmac.compare_digest()
hmac.compare_digest() is a Python function in the Hmac Module category. Constant-time comparison to prevent timing attacks. The syntax is hmac.compare_digest(a, b). Returns: Boolean. A typical example: hmac.compare_digest(h1.hexdigest(), h2.hexdigest()) # True/False. A close sibling is hmac.new(), which creates a new HMAC object for message authentication. A close sibling is hmac.digest(), which returns the digest as bytes. A close sibling is hmac.hexdigest(), which returns the digest as a hexadecimal string. A close sibling is hmac.update(), which updates the HMAC object with additional data. More about this category: HMAC message authentication — new, digest, hexdigest, compare_digest. Related Hmac Module entries: hmac.new(), hmac.digest(), hmac.hexdigest(), hmac.update(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try hmac.compare_digest() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.