You have a password and want a key out of it. In the browser, Web Crypto lets you do that with PBKDF2: you pass it the password, a salt, an iteration count, and a hash, and it gives you bits back. In encloom 2.1.0, encloom/pbkdf2 does exactly that with crypto.subtle.deriveBits. If you don't pass any options, you get a 32-byte key, a random 16-byte salt, 600,000 iterations, and HMAC-SHA-256.

That figure isn't arbitrary. The OWASP Password Storage Cheat Sheet, checked on 20 November 2026, recommends 600,000 iterations for PBKDF2-HMAC-SHA256. The PBKDF2_DEFAULT_ITERATIONS default matches that recommendation and leaves SHA-256 as the default digest. If you pass a SHA-512 digest and omit the iterations, it uses PBKDF2_DEFAULT_ITERATIONS_SHA512 (220,000), which is OWASP's figure for that hash.

Not a compliance guide and not an audit. encloom isn't audited, it isn't FIPS-140 validated, and OWASP doesn't certify libraries. This is about what the function does, what it asks you to store, and how the 2.1.0 default matches the figures OWASP recommends for the chosen digest. If you pass the iterations yourself, it also requires that floor, unless you set allowLegacyIterations.

PBKDF2, in short

PBKDF2 is defined in RFC 8018 (PKCS #5 v2.1, January 2017). I cite the specification even though it is more than five years old because the algorithm hasn't changed: RFC 8018 obsoletes RFC 2898 and is still the PKCS #5 reference for this function. Paraphrasing section 5.2, it starts from a password P, a salt S, an iteration count c, and an output length dkLen; the PRF (in practice, HMAC with a hash) is applied c times, and the output is the derived key.

Two practical consequences, also from the RFC, that matter later on:

  • The salt and the iteration count “need not be kept secret” (section 3). What you do need to store, if you're going to derive the same key again, is the output together with those parameters: the RFC says this for password checking, “the output of the key derivation function is stored (along with the salt and iteration count) for the purposes of subsequent verification of a password”.
  • If the salt is generated at random, “It should be at least eight octets (64 bits) long” (section 4.1).

What the RFC doesn't give you, and shouldn't be asked to, is a current iteration count. In section 4.2 it points to the 2010 SP 800-132 and talks about a minimum of 1,000 iterations. That figure is outdated. For today's work factor I use OWASP, not the RFC.

Why it's still around in 2026

Argon2id and scrypt are OWASP's first line today for storing passwords. PBKDF2 is still in the conversation for two concrete reasons.

The first is Web Crypto. The W3C Recommendation of 26 January 2017 lists PBKDF2, HKDF, and ECDH as derivation algorithms. I quote the non-normative description of PBKDF2: “The "PBKDF2" algorithm identifier is used to perform key derivation using the PKCS#5 password-based key derivation function version 2.0, as defined in [RFC2898] using HMAC as the pseudo-random function”. HKDF isn't meant for a password, which is a low-entropy secret; neither is ECDH. Argon2 and scrypt don't appear in that Recommendation (nor in the First Public Working Draft of Web Cryptography Level 2 of 22 April 2025). In the browser, if you want to derive a key from a password with the environment's own API, PBKDF2 is the option Web Crypto ships with.

The second is the FIPS-140 case. The Cheat Sheet itself, in the opening summary, puts it this way: “If FIPS-140 compliance is required, use PBKDF2 with a work factor of 600,000 or more and set with an internal hash function of HMAC-SHA-256.” Later it notes that PBKDF2 “is permitted by NIST SP 800-63B-4 and has FIPS-140 validated implementations”, and that in that case it “should be the preferred algorithm when these are required”. A word of caution: having a FIPS-140 validated implementation is a separate requirement. Using crypto.subtle in the browser or in Node doesn't turn encloom into a FIPS module.

SP 800-63B-4 (published in July 2025) doesn't set 600,000 iterations. In the Password Verifiers section it asks for a salted, costed password hashing function, and points to the latest revision of SP 800-132 or later NIST guidance. What it does require, and what fits what encloom returns, is that the salt and the hash be stored, and it recommends also storing a reference to the scheme and the cost factor so you can migrate.

The figure depends on the hash

OWASP says it in so many words: “The work factor for PBKDF2 is implemented through an iteration count, which should be set differently based on the internal hashing algorithm used.” In the current Cheat Sheet (20 November 2026) the list is this, quoted as is:

  • “PBKDF2-HMAC-SHA256: 600,000 iterations (recommended)”
  • “PBKDF2-HMAC-SHA512: 220,000 iterations”
  • “PBKDF2-HMAC-SHA1: 1,400,000 iterations — legacy only, do not select for new systems.”

It isn't a whim: HMAC-SHA-512 does more work per iteration than HMAC-SHA-256, so you reach a comparable cost for an attacker with fewer rounds. That's why 210,000 iterations don't mean the same thing with one hash as with the other.

Those 210,000 were, for more than three years, OWASP's figure… for SHA-512, not for SHA-256. On 23 January 2023, PR #1055 was merged (commit ba94e5c), which left the counts at 600,000 for SHA-256 and 210,000 for SHA-512. On 26 March 2026, PR #2084 (commit 02bfdad) raised SHA-512 to 220,000 and SHA-1, already legacy, to 1,400,000. In the discussion, Jeff Manico summed it up this way: “PBKDF2-HMAC-SHA512: 210,000 iterations -> Bumps to 220,000”. SHA-256 stayed at 600,000, which has been the figure marked recommended since 2023.

The default in encloom/pbkdf2 in 2.1.0 follows those figures according to the digest: 600,000 iterations with HMAC-SHA-256, and 220,000 if you choose HMAC-SHA-512.

What encloom/pbkdf2 does

The signature is pbkdf2(password, options?). password comes in as bytes (Uint8Array); encoding is up to the caller. I went through why this kind of API should use Uint8Array and not Buffer in Buffer vs Uint8Array in TypeScript crypto (and why it hurts). The password must not be empty. If you omit options, this is what happens:

  • it generates a random 16-byte salt with crypto.getRandomValues;
  • it uses PBKDF2_DEFAULT_ITERATIONS (600,000) and HMAC-SHA-256;
  • it derives 32 bytes (the default keyLength; configurable from 16 to MAX_KEY_LENGTH, 1,024) with subtle.importKey("raw", …, "PBKDF2") and deriveBits;
  • it returns { key, salt, iterations, digest }.

If you pass digest: PBKDF2_DIGEST_SHA512 and omit iterations, the count becomes PBKDF2_DEFAULT_ITERATIONS_SHA512 (220,000). If you do pass iterations, it also has to meet OWASP's minimum for the chosen digest: 600,000 with SHA-256, 220,000 with SHA-512. A lower value is rejected unless you pass allowLegacyIterations: true, which is meant for re-deriving a key you already stored (for example 210,000 with SHA-256). For new material, omit iterations or pass a value at or above the floor; don't use the legacy option.

If SubtleCrypto isn't there, the async function throws PBKDF2: Web Crypto API is not available. Async derivation uses Web Crypto; there is no npm pbkdf2 dependency. There is also pbkdf2Sync, which derives in-process with @noble/hashes and doesn't depend on subtle. It is blocking: the calling thread waits for the full count. In the browser or in a UI, you should use pbkdf2.

1. A round trip with the default

import { pbkdf2 } from "encloom/pbkdf2"; import { PBKDF2_DEFAULT_ITERATIONS, PBKDF2_DIGEST_SHA256 } from "encloom/constants"; import { utf8ToBuffer } from "encloom/helpers/encoding"; const out = await pbkdf2(utf8ToBuffer("password")); console.log(out.key.length, out.salt.length, out.iterations, out.digest); // 32 16 600000 sha256 console.log(out.iterations === PBKDF2_DEFAULT_ITERATIONS, out.digest === PBKDF2_DIGEST_SHA256); // true true 

digest is labeled the Node way (sha256 or sha512), not with Web Crypto's names (SHA-256, SHA-512). The salt changes on every call: don't expect the same key unless you reuse the salt the first call returned.

2. Store the salt, iterations, and algorithm, then re-derive

That's exactly what OWASP asks for so you can raise the work factor later: “Using a mix of hashing algorithms is easier if the password hashing algorithm and work factor are stored with the password using a standard format”. NIST SP 800-63B-4, in the same vein, says the salt and the hash SHALL be stored, and that a reference to the scheme and the cost factor SHOULD be stored “to allow migration to new algorithms and work factors”.

import { pbkdf2, pbkdf2Sync } from "encloom/pbkdf2"; import { utf8ToBuffer, bufferToHex } from "encloom/helpers/encoding"; const password = utf8ToBuffer("password"); const first = await pbkdf2(password); const again = pbkdf2Sync(password, { salt: first.salt, iterations: first.iterations, digest: first.digest, keyLength: first.key.length, }); const otherSalt = await pbkdf2(password); // new random salt console.log(bufferToHex(first.key) === bufferToHex(again.key)); // true console.log(bufferToHex(first.salt) === bufferToHex(otherSalt.salt)); // false console.log(bufferToHex(first.key) === bufferToHex(otherSalt.key)); // false 

If the key was stored with a count lower than the default, pass it explicitly and add allowLegacyIterations: true. Without that option, a value below the OWASP minimum is rejected. With 210,000 iterations and SHA-256, the output matches Node's crypto.pbkdf2Sync:

const stored = await pbkdf2(password, { salt: first.salt, iterations: 210_000, digest: first.digest, allowLegacyIterations: true, }); // stored.iterations === 210000 

The salt has to be unique and random. OWASP describes it this way: “A salt is a unique, randomly generated string that is added to each password as part of the hashing process.” And, paraphrasing the next sentence, because it's different for each password, an attacker has to attack the hashes one by one, with their salt, instead of computing one hash and comparing it against all of them. Reusing the same salt, or not generating a new one, cancels that protection. If you pass the salt yourself, it has to be at least 16 bytes, the same length as the default and above the eight-octet minimum in RFC 8018 and the 32-bit minimum in SP 800-63B-4.

3. How to set OWASP's figures yourself

pbkdf2(password) with no options uses 600,000 iterations and HMAC-SHA-256, the pair OWASP marks as recommended. If you want to make those values explicit, or use SHA-512, you can pass them yourself. With SHA-512, if you omit iterations, the default is 220,000:

import { pbkdf2 } from "encloom/pbkdf2"; import { PBKDF2_DIGEST_SHA256 } from "encloom/constants"; import { utf8ToBuffer } from "encloom/helpers/encoding"; const out = await pbkdf2(utf8ToBuffer("password"), { iterations: 600_000, digest: PBKDF2_DIGEST_SHA256, }); console.log(out.key.length, out.salt.length, out.iterations, out.digest); // 32 16 600000 sha256 
import { pbkdf2 } from "encloom/pbkdf2"; import { PBKDF2_DEFAULT_ITERATIONS_SHA512, PBKDF2_DIGEST_SHA512 } from "encloom/constants"; import { utf8ToBuffer } from "encloom/helpers/encoding"; const out = await pbkdf2(utf8ToBuffer("password"), { digest: PBKDF2_DIGEST_SHA512, }); console.log(out.key.length, out.salt.length, out.iterations, out.digest); // 32 16 220000 sha512 console.log(out.iterations === PBKDF2_DEFAULT_ITERATIONS_SHA512); // true 

In both cases the salt is still a random 16 bytes if you don't pass one, and the result returns the parameters you need to persist. If you raise the count later, old records can still be verified because they carry their own iterations.

A sanity check: with the same salt, the same iterations, the same digest, and the same key length, the output of pbkdf2 and of pbkdf2Sync matches Node's crypto.pbkdf2Sync. I checked this with 600,000 and SHA-256, with 220,000 and SHA-512, and with 210,000 and SHA-256 (the last one with allowLegacyIterations: true), at 32 bytes.

4. What it does reject

It rejects an empty password, a salt shorter than 16 bytes, a digest other than sha256 or sha512, a keyLength outside the 16–1,024 range, a count that isn't an integer ≥ 1, and an explicit count below the OWASP minimum if you don't pass allowLegacyIterations: true:

import { pbkdf2 } from "encloom/pbkdf2"; import { PBKDF2_DIGEST_SHA512 } from "encloom/constants"; import { utf8ToBuffer } from "encloom/helpers/encoding"; const password = utf8ToBuffer("password"); try { await pbkdf2(new Uint8Array(0), { iterations: 1 }); } catch (e) { console.log(e.message); // PBKDF2: password must not be empty } try { await pbkdf2(password, { salt: new Uint8Array(0) }); } catch (e) { console.log(e.message); // PBKDF2: salt must be at least 16 bytes } try { await pbkdf2(password, { salt: new Uint8Array(1).fill(1) }); } catch (e) { console.log(e.message); // PBKDF2: salt must be at least 16 bytes } try { await pbkdf2(password, { iterations: 0 }); } catch (e) { console.log(e.message); // PBKDF2: iterations must be an integer >= 1 } try { await pbkdf2(password, { iterations: 1.5 }); } catch (e) { console.log(e.message); // PBKDF2: iterations must be an integer >= 1 } try { await pbkdf2(password, { iterations: 210_000 }); } catch (e) { console.log(e.message); // PBKDF2: iterations must be an integer >= 600000 for sha256 (OWASP minimum); pass allowLegacyIterations: true to re-derive with lower counts } try { await pbkdf2(password, { iterations: 210_000, digest: PBKDF2_DIGEST_SHA512 }); } catch (e) { console.log(e.message); // PBKDF2: iterations must be an integer >= 220000 for sha512 (OWASP minimum); pass allowLegacyIterations: true to re-derive with lower counts } try { await pbkdf2(password, { digest: "sha1" }); } catch (e) { console.log(e.message); // PBKDF2: digest must be sha256 or sha512 } try { await pbkdf2(password, { keyLength: 1 }); } catch (e) { console.log(e.message); // PBKDF2: keyLength must be an integer from 16 to 1024 } 

TypeScript only allows sha256 or sha512 as digest; at runtime, a value such as "sha1" is rejected with the same message, and is not silently derived as SHA-256. The iteration floor, when you pass the count yourself, matches the OWASP minimum for the chosen digest, unless you pass allowLegacyIterations: true. That option is meant for re-deriving parameters you already stored, not for new material. Even if you set it, the count still has to be an integer ≥ 1: iterations: 0 is rejected either way.

Limits: when to prefer something else

  • If you aren't bound to Web Crypto or FIPS-140, OWASP prefers Argon2id. The Cheat Sheet puts it first: “Use Argon2id with a minimum configuration of 19 MiB of memory, an iteration count of 2, and 1 degree of parallelism.” If Argon2id isn't available, “use scrypt with a minimum CPU/memory cost parameter of (2^17), a minimum block size of 8 (1024 bytes), and a parallelization parameter of 1.” Those functions don't come with Web Crypto; PBKDF2 does.
  • The work factor has to be measured in your environment. OWASP notes, paraphrasing, that there is no magic number and that, as a general rule, computing the hash should take less than a second. On the machine used to verify this article (Linux x86_64, 8 vCPU Intel Xeon, Node 24.22.1) pbkdf2 (async) took from 81.2 to 101.8 ms with the SHA-256 default (600,000 iterations, without passing iterations), from 81.9 to 83.6 ms with the same 600,000 passed explicitly, and from 97.2 to 140.7 ms with SHA-512 and 220,000 iterations. pbkdf2Sync, with the same defaults, measured from 544.4 to 598.1 ms with SHA-256 and from 643.2 to 691.2 ms with SHA-512: it's slower here because it runs in pure JavaScript (@noble/hashes) and blocks the calling thread. In the browser or in a UI, use pbkdf2. These are indicative timings from a single class of machine, not a measure of the cost to an attacker with a GPU.
  • A count below OWASP needs allowLegacyIterations. If you pass iterations yourself, it has to reach 600,000 with SHA-256 or 220,000 with SHA-512. A lower value, for example iterations: 1000 or 210,000 with SHA-256, throws unless you pass allowLegacyIterations: true. The flag doesn't distinguish verifying an old hash from creating a new key: if you set it when registering new material, the low count is accepted. Use it only to re-derive what you already stored.
  • It doesn't manage a pepper. The Cheat Sheet presents that as an additional defense, not as a substitute for the salt, and asks you not to store it alongside the hash.
  • This isn't an audit. Everything I describe can be checked in the 2.1.0 source, but that doesn't replace an independent review.

Closing

If you derive a key with PBKDF2, check these four things:

  1. Is the salt random, unique, and a reasonable length (encloom's default is 16 bytes, which is also the minimum if you pass it yourself)?
  2. Does the iteration count match the hash you're using, not the figure for a different digest?
  3. Do you store the salt, the iterations, and the algorithm with the key, so you can raise the work factor later?
  4. Are you using PBKDF2 because Web Crypto or FIPS-140 constrains you, or would Argon2id or scrypt suit you better?

encloom/pbkdf2 helps you with 1 and 3 if the password isn't empty, the salt is at least 16 bytes, and you persist what it returns. For 2, the 2.1.0 default is 600,000 iterations with SHA-256, and 220,000 if you choose SHA-512 and omit iterations. If you pass the count yourself, it also has to meet that floor, unless you pass allowLegacyIterations: true to verify something already stored. 4 is still a design decision.

References

The examples were run with encloom 2.1.0 and Node 24.22.1.