Skip to content

PBKDF2 hash generator

Derive a PBKDF2 key or password hash from a password, salt and iteration count, and see how long it takes in your browser.

Runs in your browser. Nothing you paste is sent to us.

Inputs

A sample password and salt are filled in. Use your own; nothing is sent.

OWASP suggests at least 600,000 for SHA-256.

Derived key

PBKDF2-HMAC-SHA256
 
For new systems, Argon2id is preferred over PBKDF2. Choose PBKDF2 when you need FIPS 140 approved algorithms or compatibility.

How to use it

  1. Enter the password and a salt, or make a new random salt.
  2. Choose the hash. The iteration count fills in with OWASP’s minimum for it.
  3. Set the derived key length in bytes.
  4. Press Derive and copy the result in Base64 or hex.

What to know

PBKDF2 runs HMAC many thousands of times so each password guess is slow. The salt makes every hash different, so one guess cannot be tested against many accounts at once.

OWASP’s Password Storage Cheat Sheet recommends at least 600,000 iterations with HMAC-SHA256, 210,000 with HMAC-SHA512 and 1,300,000 with HMAC-SHA1. For new systems it prefers Argon2id.

Keycloak offers pbkdf2, pbkdf2-sha256 and pbkdf2-sha512 hashing, and Argon2 in recent versions; the realm’s password policy sets the algorithm and iterations. To build the credential Keycloak stores, use the Keycloak password hash tool.

What PBKDF2 is

PBKDF2 (Password-Based Key Derivation Function 2) turns a password into a key or a stored password hash. It is defined in RFC 8018 (PKCS #5 version 2.1) and approved by NIST in SP 800-132.

Its job is to be slow on purpose. It runs a pseudorandom function, usually HMAC with SHA-256 or SHA-512, many thousands of times. A server pays that cost once per sign-in. An attacker trying billions of guesses against a stolen hash pays it for every guess.

It also takes a salt: random bytes stored next to the hash, different for every password. The salt makes identical passwords produce different hashes, so one precomputed table cannot crack many accounts at once.

How PBKDF2 works

For each block of output, PBKDF2 computes HMAC of the salt plus a block number, then HMACs that result again and again for the given number of iterations, XORing every round into the block. The blocks are joined and cut to the requested length.

PBKDF2 (RFC 8018), for block i
U1 = HMAC(password, salt || INT(i))
U2 = HMAC(password, U1)
...
Uc = HMAC(password, Uc-1)
T_i = U1 xor U2 xor ... xor Uc        (c = iteration count)
DK  = T_1 || T_2 || ...  cut to the key length
The sample this page loads with
password:   sample password
salt:       c2FtcGxlLXNhbHQtMTIzNA==  (Base64 of "sample-salt-1234")
PRF:        HMAC-SHA256
iterations: 600000
length:     32 bytes
result:     d+KGo0IzPTKJyLQW8igawz0Z+TzT1+wIRiNdROZPWYQ=

Why not ask for a longer output

Each block of output costs the full iteration count. Asking for more output than the hash size, such as 64 bytes from HMAC-SHA256, doubles the server’s work but not the attacker’s, who can check a guess against the first block alone. Keep the output at or below the hash size: 32 bytes for SHA-256, 64 for SHA-512.

How many iterations to use

The iteration count sets the cost. OWASP’s Password Storage Cheat Sheet gives these minimums for PBKDF2:

PRFOWASP minimum iterations
HMAC-SHA256600,000
HMAC-SHA512210,000
HMAC-SHA11,300,000

These figures are tuned so each variant costs an attacker about the same. They are a floor; raise them if your servers can afford it. The tool shows how long one derivation took in your browser, which gives a feel for the cost, though servers and attackers’ GPUs run at very different speeds.

Older defaults such as 1,000 or 10,000 iterations are far too low today. Hashes stored with them should be upgraded, which systems usually do the next time the user signs in.

PBKDF2 compared with other password hashes

FunctionCost it imposesNotes
Argon2idTime and memoryWinner of the Password Hashing Competition, RFC 9106. OWASP’s first choice.
scryptTime and memoryMemory hardness slows GPU and ASIC attacks.
bcryptTime, small memoryWidely available; truncates passwords at 72 bytes.
PBKDF2Time onlyFIPS-approved; the choice when compliance requires FIPS 140 validated algorithms.

Because PBKDF2 uses almost no memory, GPUs and custom hardware run it in parallel very efficiently. That is the main reason Argon2id is preferred for new systems. PBKDF2 with a high iteration count is still an acceptable choice, and the only one of these with FIPS approval.

PBKDF2 in Keycloak

Keycloak hashes user passwords with a provider chosen in the realm’s password policy. It ships pbkdf2, pbkdf2-sha256 and pbkdf2-sha512 providers, and recent versions add Argon2. The policy’s hashing algorithm and hashing iterations settings choose the provider and the count.

Each stored credential keeps its own algorithm, iteration count and salt. When the policy changes, existing passwords stay valid and Keycloak rehashes a password with the new settings the next time its user signs in.

To build a credential in the exact JSON shape Keycloak stores, for example for a user import, use the Keycloak password hash tool. This page computes the raw PBKDF2 value only.

Changing the hashing policy affects sign-in speed for every user. Test higher iteration counts on hardware like production before rolling them out.

What this tool does and does not do

  • It runs PBKDF2 with HMAC-SHA256, HMAC-SHA512 or HMAC-SHA1 using Web Crypto, in your browser.
  • It reads the salt as text, hex or Base64, and can make a random 16-byte salt.
  • It outputs the derived key in hex, Base64 or Base64url, at any length from 1 to 1,024 bytes.
  • It derives once when the page loads and then only when you press Derive, since high iteration counts take a moment.
  • It does not produce a full password-hash string such as a PHC string or a Keycloak credential, and it does not do Argon2, bcrypt or scrypt.

How to derive a key

  1. Enter the password. It is read as UTF-8.
  2. Enter the salt in the format you have, or press New random salt.
  3. Choose the hash. The iteration count fills in with OWASP’s minimum for it; change it if you need to match an existing system.
  4. Set the key length, usually 32 bytes for SHA-256 or 64 for SHA-512.
  5. Press Derive, then copy the result in the encoding you need.

Matching another system’s hash

When the result here differs from a stored hash, one of five inputs differs. Check each:

  • The password bytes. Some systems normalize Unicode or trim whitespace first.
  • The salt bytes. A salt stored as Base64 must be decoded, not used as text.
  • The hash function, SHA-1, SHA-256 or SHA-512.
  • The iteration count.
  • The output length and encoding.
The same derivation in Node.js
node -e "console.log(require('crypto').pbkdf2Sync('sample password', Buffer.from('c2FtcGxlLXNhbHQtMTIzNA==','base64'), 600000, 32, 'sha256').toString('base64'))"

Security notes

  • Use a unique random salt of at least 16 bytes for every password. Never reuse a salt or derive it from the username.
  • The salt is not secret. It is stored with the hash.
  • A pepper, a secret added to every password and kept outside the database, can add protection if the database alone leaks. Keep it in a secrets manager, not next to the hashes.
  • Never store passwords with a single fast hash such as SHA-256, with or without salt.
  • Use real passwords only on a device you trust; the tool sends nothing, but test values are safer.

Best practices

  • For new systems, prefer Argon2id; use PBKDF2 where FIPS compliance or compatibility requires it.
  • Start from OWASP’s minimum iteration counts and review them every year or two.
  • Store the algorithm, iterations and salt with each hash so you can raise the cost later.
  • Rehash on sign-in when a stored hash uses outdated settings.
  • Rate-limit sign-in and enable brute force protection, so slow hashing cannot be turned into a denial of service.

Moving password hashes between systems

PBKDF2 is common enough that hashes can often move between systems without users resetting their passwords. That matters when migrating users into an identity provider.

Each system stores the same few parts, in its own layout. A typical modular format puts them in one string:

A common layout for stored PBKDF2 hashes (placeholders)
<algorithm>$<iterations>$<salt>$<hash>
pbkdf2_sha256$600000$<salt>$<Base64 hash>

To import such hashes into Keycloak, map each part into Keycloak’s credential fields: the algorithm onto a matching provider, the iteration count, the salt and the hash, each in the encoding Keycloak expects. Then test one account by signing in before importing the rest. If the source uses an algorithm Keycloak does not ship, users must reset their passwords or a custom provider must check the old format.

Questions

Frequently asked questions

How many iterations should PBKDF2 use?

OWASP currently recommends at least 600,000 for PBKDF2-HMAC-SHA256, 210,000 for SHA-512 and 1,300,000 for SHA-1. Treat these as minimums and raise them if sign-in stays fast enough.

Is PBKDF2 still secure?

Yes, with a high iteration count and a unique salt. It is weaker against GPU attacks than memory-hard functions such as Argon2id, which is why Argon2id is preferred for new systems.

PBKDF2 or bcrypt or Argon2?

Argon2id first, then scrypt or bcrypt, per OWASP. Choose PBKDF2 when you need FIPS-approved algorithms or must match an existing system.

How long should the salt be?

At least 16 random bytes, unique for every password. It does not need to be secret and is stored with the hash.

What key length should I use?

The hash output size: 32 bytes for HMAC-SHA256 and 64 for HMAC-SHA512. Longer output costs your server more without slowing an attacker.

Why is my PBKDF2 result different from another tool’s?

One input differs: password bytes, salt bytes, hash, iterations or length. The salt is the usual culprit, read as text in one place and as Base64 or hex in the other.

Which hashing algorithm does Keycloak use for passwords?

It depends on the version and the realm’s password policy. Keycloak offers PBKDF2 with SHA-1, SHA-256 or SHA-512, and Argon2 in recent versions; the policy’s hashing algorithm setting chooses.

What is a pepper and do I need one?

A pepper is a secret value mixed into every password before hashing, kept outside the database, for example in a secrets manager. It helps if only the database leaks. It is optional; a strong hash with a unique salt per password comes first.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.