hmac

Stdlib — SecurityPython 2.0+Advanced

Keyed-hash message authentication codes

Quick Info

Documentation
Official Docs
Python Version
2.0+
Dependencies
None — Python Standard Library
Install
Included with Python

Learn by Difficulty

Quick Example

python
import hmac
import hashlib

key = b"secret-key"
message = b"Hello, World!"

mac = hmac.new(key, message, hashlib.sha256).hexdigest()
print(f"HMAC: {mac}")

# Verify
print(f"Valid: {hmac.compare_digest(mac, mac)}")

The hmac module is part of Python's standard library. Keyed-hash message authentication codes.

Try in Playground

Tags

stdlibsecuritycryptography