Skip to content

Keycloak password hash generator

Generate a PBKDF2 password credential in the format Keycloak stores, ready for a user import, or check a password against a stored credential.

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

Password

A sample password is filled in. Whatever you type stays in your browser.

Filled in with OWASP’s suggestion for the algorithm. Match your realm’s password policy.

16 random bytes, made in your browser.

Credential

Hashing…

Credential
 
User for a realm or partial import
 
secretData and credentialData are JSON written as strings, as Keycloak exports them. Keycloak checks a password with the algorithm and iterations stored in its credential, so this works even when the realm’s policy names another algorithm.

How to use it

  1. Enter the password and pick the PBKDF2 algorithm and iterations.
  2. Keep the random salt or make a new one.
  3. Copy the credential or the user JSON for an import.
  4. To check a password, switch to Verify and paste a credential.

What to know

Keycloak stores a password as two JSON strings: secretData with the Base64 hash and salt, and credentialData with the algorithm and iteration count.

The hash is made with Web Crypto’s PBKDF2 in your browser. The password, the salt and the result never leave the page.

Keycloak checks a password with the algorithm and iterations recorded in its credential, so an imported pbkdf2-sha512 credential works even if the realm uses another algorithm for new passwords.

How Keycloak stores passwords

Keycloak never stores a password itself. It stores a hash: the result of running the password through a slow, one-way function with a random salt. At sign-in it hashes what the user typed the same way and compares the results.

Each password is a credential of type password with two parts, both JSON written as strings. secretData holds the hash and the salt, in Base64. credentialData holds the algorithm and the number of iterations. Keeping the algorithm next to the hash lets Keycloak check old passwords even after the realm moves to another algorithm.

A password credential as it appears in a user import (values shortened)
{
  "type": "password",
  "secretData": "{\"value\":\"3ZpF…==\",\"salt\":\"gKs2…==\",\"additionalParameters\":{}}",
  "credentialData": "{\"hashIterations\":210000,\"algorithm\":\"pbkdf2-sha512\",\"additionalParameters\":{}}"
}

Why you would build a hash yourself

Most of the time Keycloak makes hashes on its own, when users set or change passwords. You need to build one when users come from somewhere else and should keep their passwords, or when you prepare test users with known passwords for a staging realm, or when you want to check that a stored credential matches a password during a migration.

In each case the credential must be exactly what Keycloak expects. A wrong encoding, a hex hash where Base64 belongs, or an iteration count in the wrong field means the user cannot sign in, and the error at sign-in only says the credentials are invalid.

PBKDF2 in Keycloak

PBKDF2 runs an HMAC many thousands of times over the password and salt. Keycloak offers it with three hash functions, each with its own provider id:

Provider idHash functionOWASP suggested iterations
pbkdf2-sha512HMAC-SHA-512210,000
pbkdf2-sha256HMAC-SHA-256600,000
pbkdf2HMAC-SHA-11,300,000

The iteration numbers are the OWASP Password Storage Cheat Sheet’s suggestions, not Keycloak settings. The realm’s password policy decides what Keycloak uses for new passwords, with hashAlgorithm and hashIterations. Recent Keycloak versions also offer Argon2; this tool does not build or check Argon2 credentials.

What this tool does

Generate

Enter a password, pick the PBKDF2 variant and the iterations, and keep the random 16-byte salt or make a new one. The tool derives the key with the browser’s Web Crypto API, encodes the password as UTF-8, and writes the credential and a ready user object for a partial or realm import. The derived key is 64 bytes for pbkdf2-sha512 and pbkdf2, and 32 bytes for pbkdf2-sha256.

Verify

Paste a credential, a user with credentials, or a database row with secret_data and credential_data, then type a password. The tool reads the salt, iterations and algorithm from the credential, derives a key of the same length as the stored one, and says whether they match.

How we checked the output

The hashes this page makes were compared with Node.js crypto.pbkdf2Sync for all three variants, with plain and non-ASCII passwords, and matched. The same check passed on values read back from the page in a browser. Verifying a key of another length, made outside the tool, also passed, since the length comes from the stored value.

How to use it

  1. Choose Generate. A sample password is filled in; replace it.
  2. Pick the algorithm. Match the realm’s policy if it names one.
  3. Set the iterations. Higher is slower to guess, and also slower at every sign-in.
  4. Copy the credential, or the user object with a username of your choice.
  5. Import it with Realm settings, Action, Partial import, or inside a realm import file.
  6. Sign in as that user on a staging realm to confirm it works.

Where it helps

Moving users from another system

If the old system used PBKDF2, convert each stored hash and salt to Base64 and write them into credentials, with the right algorithm and iteration count. Users keep their passwords. Use Verify on a few known test accounts before the real import. If the old system used another scheme, such as bcrypt, Keycloak cannot check those hashes without a custom provider. Then import users without passwords and have them reset.

Test and demo realms

Seed users with known passwords without keeping the passwords in plain text in the import file. Pair it with the user import generator to build the rest of each user.

Debugging a failed sign-in after an import

Paste the credential from the export or the database and the password the user says they used. If Verify matches but Keycloak refuses the sign-in, the problem is elsewhere: a disabled user, a required action, a lockout or a federation provider in front of the local credential.

Converting hashes from another system

Old systems store PBKDF2 hashes in many shapes: hex strings, Base64 with or without padding, or one combined string with the algorithm, iterations, salt and hash separated by a character such as $ or :. Keycloak wants four separate things: the hash and the salt in standard Base64, the iteration count as a number, and the provider id.

Turn a hex hash or salt into Base64 in a shell
printf %s "$HEX" | xxd -r -p | base64

Check which hash function the old system used with PBKDF2. A hash made with HMAC-SHA-256 written as pbkdf2-sha512 will never match. If the old system added a pepper, a secret mixed in besides the salt, Keycloak cannot reproduce it, and those users need a reset.

Common mistakes

MistakeSymptomFix
Hash or salt in hexInvalid credentials at sign-inConvert both to standard Base64.
secretData as an object in a partial importImport error or unusable credentialWrite it as a JSON string, as exports do.
Wrong algorithm idInvalid credentialsUse pbkdf2-sha512, pbkdf2-sha256 or pbkdf2 exactly.
Iterations from the policy, not the old systemInvalid credentialsUse the count the hash was made with.
Password trimmed or re-encodedOnly some users failHash the exact UTF-8 bytes the user types.

Changing algorithms later

Keycloak checks each password with the algorithm and iterations stored in its own credential, so changing the realm policy does not lock anyone out. New and changed passwords use the policy’s settings. Keycloak may also re-hash a password with the current policy at the next sign-in, which moves users over without a reset. Build the policy with the password policy builder.

Security notes

The password, the salt and the result stay in your browser; nothing is sent to us. Even so, use this page for test accounts and imports, not to process passwords people use elsewhere.

A hash is not harmless. Anyone with a hash and its salt can guess passwords offline, and weak passwords fall quickly whatever the iteration count. Treat credential exports and import files as secrets, and delete them after use. To share an export, remove credentials first with the realm export sanitizer.

Best practices

  • Use a fresh random salt for every password. Never reuse one.
  • Prefer pbkdf2-sha512 with an iteration count your servers can afford at peak sign-in load.
  • Test a handful of migrated users with Verify and a real sign-in before you import everyone.
  • Mark generated test passwords temporary, so real users never keep them.
  • Plan users together with the rest of the realm when you move servers; see how migration works on managed hosting.
Questions

Frequently asked questions

What hashing algorithm does Keycloak use for passwords?

It depends on the version and the realm’s password policy. Keycloak supports PBKDF2 with SHA-1, SHA-256 or SHA-512, and Argon2 in recent versions. Each credential records the algorithm it was made with.

What is secretData and credentialData in Keycloak?

`secretData` holds the Base64 hash and salt of a credential. `credentialData` holds its algorithm and iteration count. In exports and imports both are JSON objects written as strings.

Can I import users with existing password hashes into Keycloak?

Yes, when the hashes use an algorithm Keycloak supports, such as PBKDF2. Write each one as a password credential with `secretData` and `credentialData` in the user’s `credentials` list.

Can Keycloak check bcrypt password hashes?

Not out of the box. Bcrypt needs a custom password hash provider. Without one, import users without passwords and have them reset.

How many PBKDF2 iterations should I use with Keycloak?

OWASP suggests 210,000 for PBKDF2-SHA512, 600,000 for SHA-256 and 1,300,000 for SHA-1. More iterations cost more CPU at every sign-in, so test the load on your servers.

Will changing the hashing algorithm lock users out?

No. Keycloak checks each password with the settings stored in its credential. New and changed passwords use the new policy.

Why does my imported password not work?

Usually the hash or salt is in hex instead of Base64, the iterations or algorithm do not match how the hash was made, or `secretData` is not written as a string. Check the credential with Verify.

How do I check a Keycloak password hash against a password?

Take the `secretData` and `credentialData` from an export or from the credential table, paste them into Verify with the password, and run the check. The tool derives the key with the stored salt, iterations and algorithm and compares it with the stored value.

Is it safe to type a password here?

The hashing runs in your browser and nothing is sent to us. Use it for test accounts and imports, not for passwords you use elsewhere.

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.