On this page
hashlib.pbkdf2_hmac
Prev: hashlib.new | Up: hashlib | Next: hashlib.sha1
Rel: hashlib.blake2b, hashlib.blake2s, hashlib.file_digest, hashlib.md5
Ref: docs.python.org — hashlib.pbkdf2_hmac
Tags: #public #python3 #stdlib #hashlib
Import
import hashlib
from hashlib import pbkdf2_hmac
Signature & Overview
hashlib.pbkdf2_hmac(hash_name, password, salt, iterations, dklen=None)
Password based key derivation function 2 (PKCS #5 v2.0) with HMAC as pseudorandom function.
Usage
import hashlib
derived = hashlib.pbkdf2_hmac("sha256", b"demo-input", b"unique-salt-16b", 100_000, dklen=32)
assert len(derived) == 32
Gotchas
- Always use a unique random salt (
secrets.token_bytes(16)) and high iteration count: OWASP recommends 600,000+ iterations for PBKDF2-HMAC-SHA256 in production (orscrypt/ Argon2id for memory-hardness). - Returns raw
bytes: Encode with.hex()orbase64before storing in text fields.
REPL Inspect
from hashlib import pbkdf2_hmac
help(pbkdf2_hmac)
Linked from
Related notes
- tuts/python3/stdlib_module/hashlib/new Linked here; links to this page; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/sha1 Linked here; links to this page; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/hashlib/blake2b Linked here; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/blake2s Linked here; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/file_digest Linked here; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/md5 Linked here; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/sha224 shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/sha256 shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/sha384 shared tags: #hashlib, #stdlib