Key Derivation Explained: Turning Passwords Into Real Keys

Key derivation explained in plain terms means understanding the quiet step between the password you type and the key that actually locks your files: a password is a terrible key, so something has to turn it into a good one. The central question is how a short, human, forgettable string becomes a long, random-looking key, and the answer is a function designed to be slow, salty, and stubbornly hard to guess.

Key derivation is the process of turning a password, or another low-entropy secret, into a cryptographic key of the right length and strength, using a key derivation function such as PBKDF2, bcrypt, scrypt, or Argon2. The function stretches a weak input into a strong output, and it does so deliberately slowly, so that guessing is expensive for everyone, including the attacker.

The problem it solves is one you have lived with every day without noticing: people choose passwords a computer could guess in minutes, and encryption needs keys no computer could guess in centuries. Key derivation is the bridge between those two facts, and without it, most of the encryption on your devices would be far weaker than it looks.

Key takeaways

  • Key derivation turns weak passwords into strong keys.
  • A salt makes every derived key unique, even for identical passwords.
  • Slowness is a feature: it makes guessing expensive for attackers.
  • Argon2 is the modern recommendation; PBKDF2 and bcrypt still work.
  • Never use a raw password as a key, and never skip the salt.

What key derivation is

A password and a key are different kinds of things, and confusing them is one of the oldest mistakes in cryptography. A password is short, human, and chosen for memorability, which means it has very little entropy: the average password carries perhaps forty bits of unpredictability, while a modern encryption key needs 128 or 256. A key derivation function closes that gap by feeding the password through thousands, or hundreds of thousands, of rounds of hashing, so that the output is long, uniform, and effectively random.

The salt is the second ingredient, and it is just as important as the slowness. A salt is a random value, unique to each user or each key, that is mixed in with the password before derivation starts. Two users with the same password then get completely different keys, and an attacker cannot precompute a table of answers for common passwords, because every salt demands its own table.

The salt does not need to be secret; it needs to be unique, and it is usually stored openly alongside the derived key.

The idea is older than most people realise. PBKDF2, published in 2000, was the first widely standardised approach, and it is still in use in countless systems, from Wi-Fi passwords to disk encryption. Bcrypt arrived in 1999 and added the idea of a cost parameter that grows over time, scrypt added memory hardness in 2009, and Argon2, the winner of the Password Hashing Competition in 2015, combined both ideas and is now the recommended choice for new systems.

Our guide to password hashing explains the closely related job of storing passwords safely, and our guide to hashing explains the one-way functions derivation is built on.

How key derivation works

Derivation starts with the password and a fresh salt, generated from a proper random source. The function combines them, hashes the result, and then hashes the hash, again and again, for a configured number of iterations. Each round depends on the last, so the work cannot be split across machines or parallelised away, and the final output, after the last round, is the key, trimmed or expanded to the length the encryption algorithm needs.

The iteration count is the main tuning decision, and it is a trade-off you make in plain sight. More iterations mean a slower login, usually a fraction of a second, which nobody notices, and a much slower attack, because the attacker must pay the same cost for every single guess. A common target is to make derivation take roughly a tenth of a second to half a second on current hardware, and to raise the count as hardware gets faster.

Memory hardness is the newer idea, and it matters because attackers do not guess with ordinary computers. A graphics card can try billions of simple hashes per second, but a memory-hard function forces each guess to use a large block of memory, which graphics cards have far less of per core, and which custom chips find expensive to build. Scrypt and Argon2 are memory-hard, which is why they resist the specialised hardware that made older functions vulnerable.

Argon2 comes in three flavours, and the choice is simpler than it sounds. Argon2id, the recommended variant, mixes data-independent and data-dependent memory access, giving strong resistance to both kinds of attack, and for most applications the defaults are fine: a modest memory budget, a few iterations, and a single thread.

Verification works backwards from the stored values. When a user logs in, the system takes the password they typed, the stored salt, and the stored parameters, runs the same derivation, and compares the result with the stored key. If they match, the password was right, and the comparison must be done in constant time, so that an attacker cannot learn anything from how long the check takes.

A dark workshop bench with a small brass key being shaped on an anvil, sparks glowing green in the dark
A dark workshop bench with a small brass key being shaped on an anvil, sparks glowing green in the dark, shows how key derivation works: a weak password goes in, and a strong key comes out, slowly and deliberately.

Comparing key derivation with other password defences

Key derivation is one of several ways to protect passwords, and each was built with a different emphasis. Plain hashing is fast and therefore dangerous, a pepper adds a secret value stored separately from the database, and hardware security modules move the whole job into tamper-resistant silicon, and each approach trades simplicity for strength in a different way.

The table below sets out the main contrasts between the leading approaches.

Aspect Key derivation Plain hashing Hardware module
Guessing cost High, tuned by iterations Low, billions per second High, plus physical protection
Stops precomputed tables Yes, with a unique salt No, without a salt Yes, keys never leave the device
Cost to deploy Almost nothing Almost nothing Specialist hardware
Speed for the user A fraction of a second Instant Fast, offloaded to hardware
Best for Nearly every login system Nothing, avoid it High-value keys and secrets

The practical result is that key derivation is the right default for almost every system, plain hashing is never acceptable for passwords, and a hardware module fits the keys that matter most.

Where key derivation is used

Your phone’s disk encryption uses key derivation every time you unlock it. The PIN or password you type is stretched through a derivation function, combined with hardware-backed secrets, and the result unlocks the key that decrypts your storage. The half-second pause after you type your PIN is the derivation doing its work, and it is the reason a stolen phone cannot simply be brute-forced.

Wi-Fi passwords rely on PBKDF2. When you join a WPA2 network, your passphrase is run through 4,096 rounds of derivation to produce the key that encrypts your traffic.

Password managers derive their master key from your master password. The vault is encrypted with a key that only exists after derivation, so the company holding your vault cannot open it, and an attacker who steals the vault must pay the derivation cost for every guess. This is why a strong master password, combined with a good derivation function, is the foundation of the whole system.

Encrypted messaging and file tools use derivation to turn a passphrase into a key. Tools that encrypt a file with a password you choose are really deriving a key from that password, and the security of the file depends entirely on the derivation parameters and the strength of the passphrase, not on the encryption algorithm, which is the easy part.

Web logins store derived values rather than passwords. When a site says it hashes your password, what it should mean is that it runs a key derivation function with a unique salt and stores the result, so that a database breach does not hand attackers your password, only a value that is expensive to reverse.

Strengths and limits

The greatest strength of key derivation is that it makes weak inputs survivable. People will keep choosing memorable passwords, and derivation is the honest response: accept the weakness, and make guessing so expensive that even a weak password takes too long to break. It is a practical answer to a human problem, not a lecture about choosing better passwords.

It is also a strength that derivation is cheap to deploy and easy to get right. The functions are standardised, the libraries are mature, and the parameters are well understood, which means a small team can protect its users properly with a few lines of code and no specialist hardware.

The limits are real, though. Derivation cannot save a truly awful password: if the password is “password123”, no amount of slowness will protect it, because it will be among the first guesses.

Key derivation checklist

  • Use Argon2id for new systems; PBKDF2 or bcrypt are acceptable for existing ones.
  • Generate a fresh, random salt for every password, at least 128 bits.
  • Tune the cost so derivation takes roughly a tenth to half a second.
  • Store the salt and parameters openly alongside the derived value.
  • Never use a raw hash, or a password directly, as a key.
  • Compare derived values in constant time to avoid timing leaks.
  • Review and raise the cost parameters as hardware improves.
  • Combine derivation with a strong password policy, not instead of one.
  • Consider a pepper, stored separately, for your most sensitive systems.

Frequently asked questions

What is key derivation in simple terms?

It is the process of turning a password into a proper cryptographic key by running it through a slow, salted function many times, so the result is long and random-looking even though the input was short and human.

What is the difference between key derivation and password hashing?

They are close cousins. Password hashing stores a derived value so a login can be checked, while key derivation produces a key that is actually used to encrypt something, but both use the same slow, salted functions.

Why does key derivation need to be slow?

Because the attacker must pay the same cost for every guess, so a function that takes half a second for a legitimate login takes half a second per guess for the attacker, which turns millions of guesses into years of work.

What is a salt, and why does it matter?

A salt is a random value mixed in with the password before derivation, unique to each user, which stops attackers from precomputing answers for common passwords and makes identical passwords produce different keys.

Which key derivation function should I use?

Argon2id for new systems, because it is memory-hard and resistant to specialised hardware. PBKDF2 and bcrypt are still acceptable where they are already in use, with a properly tuned cost.

Can key derivation protect a weak password?

Only up to a point. It makes guessing expensive, but a password from the top of every common-password list will still be guessed quickly, so derivation is a safety net, not a substitute for a decent password.

The bottom line

Key derivation explained in one line is this: take a weak human password, add salt, stir slowly thousands of times, and out comes a key worth trusting.

It is the unglamorous step that makes most of the encryption on your devices actually work, and the reason your PIN can protect a phone full of secrets.

This article is general information about how key derivation works, not advice about choosing security settings for a particular system.

Latest articles

Scroll to Top