← Cryptography guide

K062 / Hashes, MACs and key derivation

PBKDF2

PBKDF2 key derivation · Survey date 2026-12-05

PBKDF2 is a widely used key derivation function that derives cryptographic keys from passwords.

CRYPTOGRAPHY LAB / K062

Cryptography Lab · PBKDF2

Run real computations and inspect intermediate states step by step.

Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.

Scope: Toy educational example

PBKDF2-HMAC-SHA-256 (32 B)

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Reference ↗

Open lab →

Definition and overview
PBKDF2 is a widely used key derivation function that derives cryptographic keys from passwords. Source document ↗
Classification and reversibility
Hash/MAC-based KDF, not encryption or encoding; rederive key from same inputs, no decryption/decoding. Source document ↗
Key or secret requirements
Password is secret; inputs include salt, PRF, iteration count and output length. Source document ↗
Operating principle and structure
PRF (e.g. HMAC) takes password and salt+block index; iterate c times, XOR and concatenate needed blocks. Source document ↗
Key size, block size and parameters
Inputs PRF, password, salt, c, dkLen; block count ceil(dkLen/hLen); implementation output-length limit. Source document ↗
Security strength and recommendation
Widely standardized/validated, but low RAM usage disadvantages GPU resistance. Prefer Argon2id for new systems; PBKDF2 for FIPS requirements. Source document ↗
Known attacks and vulnerabilities
Vulnerable to GPU/ASIC parallel guessing; low iterations, weak hash or improper salt increase dictionary-attack risk. Source document ↗
Standards and certification
PKCS#5/RFC 2898, RFC 8018, NIST SP 800-132; FIPS-140 validated implementations exist. Source document ↗
Typical uses
Password hashing, AES key derivation and SCRAM/SASL authentication. Source document ↗
Implementations, libraries and tools
PyCryptodome, Go crypto/pbkdf2, WebCrypto and Laminas Crypt. Source document ↗
Decryption or decoding
No PBKDF2 decryption/decoding; rederive same key with stored salt, count and PRF then decrypt with AES-GCM etc. Source document ↗
Advantages
Adjustable iteration cost hinders dictionary/rainbow-table attacks; flexible output length and wide support. Source document ↗
Limitations and cautions
Low memory favors GPU attackers; weak defaults, low counts or HMAC-SHA1 can be risky. Consider Argon2id for new systems. Source document ↗
Distinguishing encryption, encoding and hashing
PBKDF2 is key derivation, not encryption, encoding or decryption. Use it for key generation and AES-GCM for actual encryption. Source document ↗

Practical examples

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

Example

User passphrase, random salt, iteration count and HMAC-SHA-256 derive 256-bit key for AES-GCM. To decrypt, use stored salt, IV and ciphertext, rederive same key and decrypt.

Procedure

Derive from password/random salt/PRF/count/dkLen and store parameters. Encrypt with derived key via AEAD and store IV/nonce/tag. Rederive for decryption and discard on authentication failure. Base64 is separate encoding.

Scenario

Client-side encrypted storage derives file keys from passphrases; server stores salted PBKDF2 password hashes. For FIPS-140 use validated implementation and sufficient iterations.

Pitfalls and alternatives

Avoid low counts, weak hashes such as HMAC-SHA1, fixed/reused salt and unchecked defaults. No PBKDF2 decryption; consider Argon2id/scrypt for GPU risk or validated PBKDF2-HMAC-SHA-256 with sufficient iterations for FIPS. Beware binary/string encoding mismatch.

Diagram source ↗

References