PBKDF2: Password-Based Key Derivation
What you'll learn: How PBKDF2 transforms weak passwords into strong cryptographic keys while defending against brute-force attacks.
The Problem with Password-Derived Keys
In previous lessons, you learned that KDFs generate cryptographic keys. But what if your starting material is a password chosen by a human? Passwords are typically weak—short, predictable, and reused. If an attacker steals your encrypted data, they can try billions of password guesses per second to find the key.
How PBKDF2 Works
PBKDF2 (Password-Based Key Derivation Function 2) deliberately slows down key derivation to make brute-force attacks impractical. Think of it like a moat around your castle: the attacker must cross it for every single guess.
PBKDF2 takes four inputs:
- Password – the weak secret from the user
- Salt – a random value unique to this password (prevents rainbow table attacks)
- Iteration count – how many times to repeat the hashing process (e.g., 100,000 times)
- Desired key length – how many bytes you need
It repeatedly applies a hash function (usually SHA-256) to the password and salt, mixing the results through thousands or millions of iterations. Each iteration adds computational cost.
Defense Against Brute-Force
Without PBKDF2, an attacker might test 1 billion passwords per second. With PBKDF2 at 100,000 iterations, that drops to 10,000 passwords per second—a 100,000× slowdown. For legitimate users logging in once, this delay is barely noticeable (a fraction of a second). For attackers trying billions of guesses, it becomes prohibitively expensive.
The salt ensures that even identical passwords produce different keys, preventing precomputed attack tables.
Key Takeaway: PBKDF2 uses salts and high iteration counts to transform weak passwords into strong keys while making brute-force attacks computationally expensive—your legitimate slowdown is the attacker's nightmare.