Python hmac Module
Example
Compute an HMAC (SHA256) hex digest:
import hmac
import hashlib
sig = hmac.new(b"key", b"Linus", hashlib.sha256).hexdigest()
print(sig)
Try it Yourself »
Definition and Usage
The hmac module implements keyed-hashing for message authentication as described by RFC 2104.
Use it to sign messages and verify integrity using a shared secret key.
Members
Member | Description |
---|---|
new() | Create a new HMAC object using a key, message and digestmod. |
compare_digest() | Securely compare two digests to avoid timing attacks. |