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 for | Sizes here |
|---|---|---|---|
| RSA | RSA | RS256, PS256 signatures; RSA-OAEP encryption | 2048, 3072, 4096 bits |
| Elliptic curve | EC | ES256, ES384, ES512 signatures | P-256, P-384, P-521 |
| Symmetric | oct | HS256/384/512 HMAC; A128GCM, A256GCM, A128KW, A256KW | 128 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,alganduseset. - 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.
{
"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
- Choose RSA, EC or Symmetric.
- Choose the size, curve or algorithm.
- Choose how the
kidis made: the RFC 7638 thumbprint, or random hex. - Copy the private key and store it where your service reads secrets.
- 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
usevalues. - 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
algunset. 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.
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
- Generate the new key with the same options and a new
kid. - Add the new public key to your published key set, next to the old one.
- Wait until verifiers have refreshed their cached sets.
- Start signing with the new private key.
- 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
kidand setalganduse. - 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.