If a password becomes a long encryption key, does that mean an attacker now has to guess the entire key, or can they still just guess the password? That distinction is where many explanations of key derivation go wrong.
A longer output doesn't automatically create a stronger secret. To choose a key derivation function, you need to understand what you start with, what an attacker can obtain, and which constraints your application must satisfy.
What a Key Derivation Function Does
A key derivation function (KDF) takes secret input and supporting parameters, often including a salt, and produces cryptographic key material in the form an algorithm needs. For a developer, it's the adapter between the secret a person can supply and the key a cipher can accept.
Think of a password KDF as a slow, repeatable blender. The same ingredients and settings produce the same smoothie, and you can't separate the smoothie back into its original fruit. But the analogy has a limit: an attacker can try likely ingredients, blend them, and compare the result.
That's why you can't treat a password as a ready-made encryption key. People choose secrets with uneven lengths and predictable patterns, while encryption APIs require precisely formatted key material.

The ingredients and the jobs
Suppose a developer is building an encrypted notebook. The input secret is the user's passphrase; the salt is a randomly generated, nonsecret value associated with that notebook. The iteration count controls repeated computation in an iteration-based password KDF, and the output key is what the encryption code receives.
Different KDFs serve different purposes:
- Password-based encryption: Derive a usable encryption key from a passphrase for a notebook, disk, or chat channel.
- Subkey derivation: Use HKDF to turn a strong master secret into separately labeled keys for different purposes.
- Password verification: Derive a value suitable for checking a submitted password without storing the original password.
The slow-blender model fits password stretching, not every KDF. A function working from an already unpredictable secret may need separation between uses rather than deliberate slowness.
Mental check: Matching secret bytes, salt, algorithm, and settings produce matching keys. Changing the password should produce an unrelated-looking result, not a slightly edited key.
How a Key Derivation Function Turns a Secret into a Key
A derived key is like a duplicate made from instructions rather than from a mold. The sender and recipient never pass the finished key across the table. They share the same secret, the same public recipe, and a library that follows the recipe in the same order.
The process diagram shows the broad flow. The implementation needs more detail than the boxes suggest.

A worked example makes the recipe concrete. Suppose a chat channel uses the access key lantern-copper-river-42, a per-channel salt, PBKDF2-HMAC-SHA-256, 100,000 iterations, and a 256-bit output. A browser can feed those values into a cryptographic library and receive a 256-bit AES key. Another browser that supplies the same bytes, salt, algorithm, and settings gets the same key. Change one word, one iteration count, or one byte of the salt, and the result changes.
Convert the secret into bytes. Choose an explicit text encoding, such as UTF-8, and document any normalization policy. Visually similar text is not necessarily the same byte sequence, so inconsistent preprocessing can prevent decryption.
Supply the channel's random salt. Generate it with the platform's cryptographic random generator and preserve it with the derivation parameters. Its purpose is to separate otherwise identical password-based derivations.
Invoke the selected primitive through a library. In PBKDF2 with HMAC-SHA-256, the password supplies the HMAC key, while the initial block computation incorporates the salt and a block index. This is a defined construction, not permission to invent a custom hash loop.
Perform the configured repeated work. PBKDF2 feeds each round's result into the next computation and combines the round outputs with XOR. Taking the final result of repeated hashing is not equivalent to PBKDF2.
Request the cipher's required key length. The library derives enough blocks and takes the required output bytes. A longer requested output does not repair an easily guessed input.
Hand the derived key to the cipher. Release the password and intermediate buffers when they are no longer needed. In browser JavaScript, garbage collection means you should not promise that every copy can be securely erased.
A password KDF and a subkey KDF solve different problems. A password KDF works like a tollgate that makes each guess expensive. That matters when the input is human-readable and may be guessed offline after ciphertext is stolen. HKDF works more like a label maker for strong input material. It extracts and expands an already unpredictable secret into separate labeled keys, such as one key for messages and another for files.
The choice depends on the attacker model and the input. A human-chosen access key needs deliberate password-hardening work because an attacker can try guesses locally. A random high-entropy master secret usually needs clean separation between uses more than extra guessing resistance. PBKDF2 can be a reasonable fit for the first case when its settings are explicit and benchmarked. Argon2id is another password-oriented option. HKDF belongs in the second case, where stretching a strong secret adds little.
This is also why derivation and encryption should be kept separate in your mental model. Derivation produces the correctly shaped key. Encryption uses that key to protect bytes. Ciphar applies that split in a browser flow, deriving AES keys from access keys while keeping the access key and derived key off the server; its guide to how encryption keys work gives the surrounding model. Earlier guidance on encryption at rest also exists in Cloudvara's compliance-ready encryption for accounting practices, though a KDF choice alone does not establish compliance.
Salts, Iteration Counts and Output Length Explained
| Parameter | Role | Typical value | Risk if weak |
|---|---|---|---|
| Salt | Separates derived keys and blocks reusable precomputed tables | At least 128 random bits, required for the random portion by NIST SP 800-132 | Repeated derivation inputs permit repeated keys and reusable guessing work |
| Iteration count | Multiplies computation for each guess | A documented, benchmarked password-hardening setting | Cheap offline guessing after ciphertext theft |
| Pseudorandom function | Supplies the repeated cryptographic operation | HMAC-SHA-256 | An unsuitable primitive can undermine the construction |
| Output length | Matches the destination algorithm's key requirement | The exact length required by the selected AES variant | Invalid key length or unintended use of a weaker cipher configuration |
| Derivation metadata | Records the complete recipe | Versioned settings stored with each channel or record | Clients silently derive incompatible keys |
A salt works like a public recipe identifier, not a second password. Generate a fresh salt for each independent channel, then keep it fixed for that channel's derivation profile so participants can reproduce its key. Storing it beside ciphertext doesn't reveal the password or derived key.
The iteration count is closer to an adjustable amount of labor. Raising it increases legitimate derivation time and the computation required for each password guess. NIST's practical direction is to choose the largest count that's acceptable on the target devices, rather than assuming one setting suits every environment.
Match the recipe to the cipher
The pseudorandom function, or PRF, is the cryptographic building block used inside PBKDF2. HMAC-SHA-256 is a common choice, but the complete construction matters more than a hash name in a configuration file. Don't substitute a different operation while keeping the PBKDF2 label.
Output length is a compatibility requirement, not an entropy dial. Request the key length your cipher expects; a short result may be rejected instead of accepted as a weaker key. The AES-GCM encryption guide explains the cipher that consumes that derived key.
Finally, record more than the salt and count. Include the algorithm, PRF, requested output length, encoding rules, and profile version so future clients can reproduce the derivation.
Implementation check: Write down every input needed to recreate a key. If any value exists only as an undocumented default in today's code, your format isn't ready for migration.
The trade-off is setup time versus guessing cost, not security versus inconvenience in the abstract. Inventory your actual parameters, justify each choice, and test the resulting delay on the slowest devices you intend to support.
PBKDF2, scrypt, bcrypt and Argon2id Compared
| Algorithm | Memory-hard | Reference | Baseline setting |
|---|---|---|---|
| PBKDF2-HMAC-SHA-256 | No | NIST SP 800-132 and RFC 8018 | 600,000 iterations in OWASP's password storage guidance, including its FIPS-140-oriented recommendation |
| scrypt | Yes | The scrypt specification | Tune memory and CPU cost to the deployment |
| bcrypt | Fixed, small memory footprint, not tunable memory hardness | Established password-verification implementations | Tune the work factor; primarily a legacy password-storage choice |
| Argon2id | Yes | The Argon2 specification | OWASP's preferred password KDF; tune memory, iterations, and parallelism |
The visual comparison helps separate adjustable computation from adjustable memory requirements.

Think of an attacker running a workshop full of password-guessing machines. If every job needs little working space, the attacker can pack many jobs together. A memory-hard function makes each job occupy substantial workspace, limiting parallelism or forcing the attacker to buy more memory capacity and bandwidth.
That doesn't make guessing impossible. It changes the economics of running guesses in bulk, particularly on specialized parallel hardware. PBKDF2 imposes repeated computation but doesn't offer the same configurable memory requirement.
Choose for the deployment, not the label
Argon2id is generally the preferred starting point for a new password-based system when a maintained implementation is available. scrypt offers another memory-hard approach. bcrypt remains relevant to existing password-verification systems, but it isn't the natural general-purpose tool for deriving encryption subkeys.
PBKDF2 remains appropriate when interoperability, validated implementations, or native browser APIs constrain the design. Browser WebCrypto provides PBKDF2 rather than native Argon2 support; introducing another implementation adds dependencies and deployment decisions that deserve review.
For FIPS requirements, selecting PBKDF2 isn't sufficient on its own. The cryptographic module and its validated configuration also matter.
Use the accompanying video as another explanation of the concepts, not as a substitute for implementation documentation.
The useful verdict isn't that PBKDF2 is universally secure or universally obsolete. Prefer memory hardness for guessable human passwords where practical; choose PBKDF2 deliberately when platform or standards requirements justify it, and evaluate the input secret separately.
How a Chat App Uses a Key Derivation Function
At Ciphar, channel creation starts in the browser. We generate the channel name and a random access key locally, using the browser's native cryptographic random source. The access key uses words from a fixed dictionary so someone can read it aloud or paste it into another encrypted medium.
Readable words aren't the problem by themselves. The important distinction is whether software selects them randomly or a person chooses a memorable phrase. Without the dictionary size and selection details, you shouldn't assign a numerical entropy estimate to the result.
Our browser derives the encryption key from that access key and a per-channel salt using PBKDF2-HMAC-SHA-256 with 100,000 iterations, producing a 256-bit AES key. The derived key stays in browser memory and is never sent to the server; the access key also never touches the server.
From invitation to admission
- The sender shares access separately: They send the channel link and access key through a trusted medium. The access key leaves their device only when they choose to share it.
- The recipient derives locally: They open the link and paste the access key. Their browser runs the channel's derivation profile rather than requesting a decryption key from the relay.
- The browser checks the result: Admission requires deriving the matching key and successfully decrypting the channel's encrypted test blob. An incorrect key doesn't admit the participant.
- The relay handles encrypted material: It stores ciphertext and the supporting IVs, authentication tags, salt, and expiry information, not plaintext or derived keys.
This encrypted browser app design illustrates why key derivation belongs on the device in this architecture. The server can relay encrypted content without participating in the secret-to-key conversion.
What the iteration setting means
Our compatibility-oriented setting isn't a general-purpose target for user-chosen passwords. It's below the password-hardening recommendation in the algorithm comparison, so the unpredictability of the generated access key carries much of the protection against guessing.
A random access key can be difficult to guess before any stretching occurs. A predictable phrase remains vulnerable even when its derived output looks perfectly random. The reusable lesson is to evaluate the secret-generation process, not just the appearance or length of the final AES key.
Choose a Key Derivation Function and Correct the Common Claims
| Situation | Suggested function | Key settings |
|---|---|---|
| Random high-entropy channel key | PBKDF2-HMAC-SHA-256 can suit a compatible channel design | Unique cryptographic salt; benchmarked count; versioned profile |
| Human passphrase chosen by users | Argon2id | Tune memory, iterations, and parallelism for supported devices |
| FIPS compliance required | PBKDF2-HMAC-SHA-256 | Use an appropriate validated implementation and documented password-hardening profile |
| Browser-only, WebCrypto available | PBKDF2 through WebCrypto | Test low-end phones; native WebCrypto doesn't provide Argon2 |
These are starting points, not interchangeable recipes. A random master secret that only needs separated subkeys may call for HKDF instead of password stretching. Conversely, allowing users to replace generated secrets with memorable phrases changes the threat model even if the interface looks unchanged.
OWASP's Password Storage Cheat Sheet recommends an Argon2id baseline of 19 MiB of memory, two iterations, and one degree of parallelism. Treat baseline settings as inputs to an engineering review, not proof that every application using them is secure.
The decision starts with the kind of secret you're protecting.

Correct the claims that cause design errors
- The salt must be hidden: No. Its job is separation between derivations, not secrecy. Protect its integrity as part of the stored profile, but don't treat access to it as equivalent to access to the key.
- More iterations fix any password: They increase the cost of testing candidates, not the number of plausible candidates. An attacker with ciphertext, salt, IVs, and authentication tags can derive a candidate key and test whether AES-GCM authentication succeeds offline.
- Standardized means strongest available: Standardization supports interoperability and defined implementations. It doesn't remove the need to consider parallel guessing, memory cost, and the quality of the input.
- The KDF encrypts the message: The KDF produces key material. The cipher encrypts and authenticates the content, with its own requirements for nonce handling and correct use.
- Rate limits stop password guessing: They restrict attempts that reach your service. Someone testing stolen ciphertext on their own hardware doesn't encounter your access endpoint or trigger its failed-access alerts.
A server-side deletion policy can't erase a ciphertext copy an attacker already obtained. Evaluate offline guessing against that copy, not just against the live service.
Set and maintain a defensible profile
Start by identifying who could obtain ciphertext and whether the secret is machine-generated or human-chosen. Select the function around those conditions, then benchmark the actual implementation on representative low-end phones, desktops, and browsers.
Set an acceptable user-perceived delay before choosing the work setting. Measure within that budget, document the result, and record the complete derivation profile with each encrypted record or channel. Don't change a shared default without notice and expect old ciphertext to remain interoperable.
Reassess the profile as devices, libraries, and attacker capabilities change. Plan how existing encrypted data will migrate, which clients can read each profile, and when re-derivation requires the original secret. A defensible key system includes that lifecycle, not just a successful call to a cryptographic API.
Ciphar offers browser-based encrypted conversations with access keys generated locally and encryption keys derived on the device, without sending either secret to the relay. Visit Ciphar to review the security model and try creating a channel, then share its access key through a separate trusted medium.



