Skip to content

JWK generator

Generate an RSA, EC or symmetric key as a JWK, with a kid, ready to use in tests or to publish as a key set.

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

Options

Keys are made with your browser’s Web Crypto and never leave this page. A new key is made each time you change an option.

Generated key

Private key (JWK)
 

How to use it

  1. Pick the key type: RSA, EC or symmetric.
  2. Pick the size, curve or algorithm.
  3. Choose the kid: the key’s thumbprint or a random value.
  4. Copy the private key, the public key, the JWKS or the PEM forms.

What to know

Keys are made by your browser’s Web Crypto and never leave the page. Changing an option makes a new key.

RSA keys need 2048 bits or more. EC keys are shorter for the same strength: P-256 for ES256, P-384 for ES384, P-521 for ES512.

Keycloak can use a key you bring: add an rsa key provider under Realm settings, Keys, with the private key in PEM. Give it a higher priority than the current key to make it the active one.

What a JSON Web Key is

A JSON Web Key (JWK, RFC 7517) is a key written as a JSON object. It names the key type in kty, carries the key’s numbers as Base64url strings, and can add metadata: a key id (kid), an intended use (use) and an algorithm (alg).

OAuth and OpenID Connect use JWKs everywhere keys are exchanged: identity providers publish their public keys as a key set, clients register keys, and libraries load keys from JSON. A generator that writes keys straight into this form saves a conversion step.

Key types you can generate

Type`kty`Used forSizes here
RSARSARS256, PS256 signatures; RSA-OAEP encryption2048, 3072, 4096 bits
Elliptic curveECES256, ES384, ES512 signaturesP-256, P-384, P-521
SymmetricoctHS256/384/512 HMAC; A128GCM, A256GCM, A128KW, A256KW128 to 512 bits

RSA and EC keys come as pairs: a private key that signs or decrypts, and a public key that verifies or encrypts. A symmetric key is one secret shared by both sides.

RSA or EC?

RS256 works with almost every library and is the default in many identity providers, including Keycloak. EC keys are much smaller for comparable strength, so tokens and key sets are shorter, and signing is fast. Choose EC when every party that verifies your tokens supports it; otherwise choose RSA with 2048 bits or more.

What the generator produces

  • The private key as a JWK, with kid, alg and use set.
  • The public key as a JWK, without any private members.
  • A JWKS containing only the public key, ready to publish.
  • For RSA and EC, the public key as PEM (SPKI) and the private key as PEM (PKCS #8).

The use member follows the algorithm: sig for signature algorithms, enc for RSA-OAEP, AES-GCM and AES key wrap.

Shape of a generated EC private key (values shortened)
{
  "kty": "EC",
  "kid": "6Wm3…",
  "alg": "ES256",
  "use": "sig",
  "crv": "P-256",
  "x": "…",
  "y": "…",
  "d": "…"
}

How keys are made

The page calls crypto.subtle.generateKey, the browser’s Web Crypto API. Random numbers come from the browser’s cryptographically secure generator. Symmetric keys are filled with crypto.getRandomValues.

Keys exist only in the page. Nothing is sent to us, and the key is gone when you close the tab or change an option. Copy what you need before you leave.

How to generate a key

  1. Choose RSA, EC or Symmetric.
  2. Choose the size, curve or algorithm.
  3. Choose how the kid is made: the RFC 7638 thumbprint, or random hex.
  4. Copy the private key and store it where your service reads secrets.
  5. Copy the public JWK or JWKS and publish it, or register it with the other party.

Each change of option makes a new key. Press “Generate another” for a fresh key with the same options.

Key ids: thumbprint or random

A thumbprint kid is computed from the public key (RFC 7638), so anyone can recompute it and it never needs to be stored separately. A random kid says nothing about the key but is shorter. Either works as long as each key in a set has a different one.

Use cases

A client that authenticates with a signed JWT

A Keycloak client can use “Signed JWT” (private_key_jwt) instead of a client secret. The client signs a short assertion with its private key, and Keycloak checks it with the public key. Generate an RSA or EC key here, keep the private key in your app, and give Keycloak the public key through a JWKS URL or by importing a certificate on the client’s Keys tab.

Test fixtures

Tests that check token handling need keys that are not production keys. Generate a pair, sign test tokens with the private key in your test code, and configure the code under test with the public JWKS.

HMAC secrets

A symmetric HS256 key from here is 32 random bytes, Base64url-encoded in k. That is a good shared secret for HMAC-signed tokens between two services you control.

Bringing your own realm key

Keycloak normally generates its own realm keys. If you need a specific key, add an rsa key provider under Realm settings, Keys, Providers and paste the private key in PEM, with a certificate if you have one. Give it a higher priority than the current key to make it the active signing key.

Mistakes to avoid

  • Publishing the private JWK. Only the public key or public JWKS belongs in a published key set.
  • Using one key for both signing and encryption. Keep separate keys with separate use values.
  • RSA keys shorter than 2048 bits. The generator does not offer them.
  • Reusing a test key in production. Generate production keys where they will be stored.
  • Leaving alg unset. A key tied to one algorithm cannot be misused with another.

Signing with a generated key

Once you have a private JWK, most JWT libraries can load it directly. In the browser or in Node.js, Web Crypto can import it too.

Signing an ES256 signing input with Web Crypto
const key = await crypto.subtle.importKey(
  'jwk', privateJwk, { name: 'ECDSA', namedCurve: 'P-256' }, false, ['sign'],
);
const signature = await crypto.subtle.sign(
  { name: 'ECDSA', hash: 'SHA-256' }, key, new TextEncoder().encode(signingInput),
);

Remove use, alg and kid before importing if your library complains about them; Web Crypto checks that a JWK’s alg fits the algorithm you ask for.

Rotating a key you generated

  1. Generate the new key with the same options and a new kid.
  2. Add the new public key to your published key set, next to the old one.
  3. Wait until verifiers have refreshed their cached sets.
  4. Start signing with the new private key.
  5. Remove the old public key after every token it signed has expired.

Publishing before signing is the important part. A verifier that sees a kid it does not know yet will reject the token.

Symmetric keys for encryption

The symmetric options include AES keys for JWE: A128GCM and A256GCM for direct content encryption with alg: dir, and A128KW and A256KW for wrapping content keys. Their use is enc. Both sides must hold the same key, so share it through a secret store, never in a URL, a ticket or an email.

Security notes and limits

Browser-generated keys use a sound random source. The risk is in handling: a private key copied through a clipboard, a chat or a ticket can leak. For long-lived production keys, many teams generate keys inside the system that stores them, such as a key management service or a hardware module, so the private key never exists in plain form elsewhere.

Ed25519 keys and RSA-PSS-only keys are not offered here. An RSA key from this tool can sign PS256 as well as RS256; the alg you choose only records which one you intend.

Best practices

  • Give every key a unique kid and set alg and use.
  • Rotate signing keys on a schedule; publish the new public key before you start signing with it.
  • Keep the old public key published until all tokens it signed have expired.
  • Store private keys in a secret store, never in source control.
Questions

Frequently asked questions

Is it safe to generate keys in a browser?

Web Crypto uses the browser’s secure random number generator, which is suitable for keys. The bigger risk is handling the private key afterwards, so for production keys many teams generate them where they will be stored.

Which key should I publish?

Only the public key or the public JWKS. The private key and any symmetric key must stay secret.

Which algorithm should I choose?

RS256 is supported almost everywhere. ES256 gives smaller keys and signatures. Use RSA-OAEP keys only for encryption, and HS256 only when both sides share the secret.

What RSA key size should I use?

At least 2048 bits. 3072 or 4096 bits give more margin at the cost of slower signing and larger signatures.

What is a JWK thumbprint?

A SHA-256 hash over the key’s required members in a fixed order (RFC 7638), Base64url-encoded. It identifies the key and is a common choice for `kid`.

Can I use a generated key as a Keycloak realm key?

Yes. Add an `rsa` key provider under Realm settings, Keys, Providers with the private key in PEM, and give it a higher priority than the current key. Keycloak then signs new tokens with it.

Is the key stored anywhere?

No. It exists only in the open page and is replaced when you change an option or close the tab.

Why does the key change when I change the kid option?

Every option change generates a fresh key, so that what you see always matches the options shown. Copy a key before changing options if you want to keep it.

Can I generate an Ed25519 key here?

Not at the moment. The generator makes RSA, EC and symmetric keys. Ed25519 keys can be converted with the JWK to PEM and PEM to JWK tools if you create them elsewhere.

What is the difference between the private JWK and the PEM private key?

They hold the same key in two formats. The JWK is JSON with named members; the PEM is PKCS #8 in Base64. Use whichever your software reads.

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.