Skip to content

RSA key pair generator

Generate an RSA key pair in your browser and get it as PEM (PKCS#8 or PKCS#1) and as a JWK with its thumbprint as the kid.

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

Settings

Sets the JWK’s alg and use. Keep a key to one purpose: signing or encryption.

Keep the private key private
The key was made in this browser and is not stored anywhere. For production, generating the key where it will be used avoids copying it at all.

Key pair

Private key (PEM)
 
Public key (PEM)
 
Public key (JWK)
 
The kid is the key’s RFC 7638 thumbprint, so the same key always gets the same id.

How to use it

  1. Choose the key size: 2048, 3072 or 4096 bits.
  2. Choose the algorithm the JWK should name: RS256, PS256 or RSA-OAEP-256.
  3. Choose PKCS#8 or the traditional PKCS#1 PEM format.
  4. Copy the private key, the public key and the public JWK.

What to know

The key is made with Web Crypto in your browser, with public exponent 65537. It is not stored and never leaves the page unless you copy it.

PKCS#8 (BEGIN PRIVATE KEY) is the modern container most tools read. PKCS#1 (BEGIN RSA PRIVATE KEY) is the older RSA-only format some software still expects.

Keycloak makes and rotates realm keys itself with its rsa-generated key provider. To bring your own key, add an rsa key provider in the realm’s Keys settings and give it the private key, and a certificate if you have one.

What an RSA key pair is

RSA is a public-key algorithm. A key pair has a private key, which only its owner holds, and a public key, which anyone can have. What the private key signs, the public key verifies. What the public key encrypts, only the private key decrypts.

In identity systems RSA is mostly used for signatures. An identity provider signs tokens and SAML assertions with its private key, and every application checks them with the public key. Because verifiers need only the public key, many services can trust one issuer without sharing a secret.

This tool generates RSA key pairs in your browser with Web Crypto and gives you the keys in the formats other software reads: PEM in PKCS#8 or PKCS#1, and JWK.

Key sizes and security strength

RSA strength grows slowly with key size. NIST SP 800-57 maps RSA moduli to comparable symmetric strength:

RSA modulusSecurity strengthComparable EC curve
2048 bits112 bitsP-224
3072 bits128 bitsP-256
7680 bits192 bitsP-384
15360 bits256 bitsP-521

2048 bits is the accepted minimum today and what most identity providers use for token signing. 3072 bits gives a longer margin. 4096 bits is common for long-lived keys, though it makes signing slower for a modest gain.

Generation time grows quickly with size. A 2048-bit key takes a moment in a browser; a 4096-bit key can take several seconds.

The formats this tool produces

The same key can be written in several containers. They hold the same numbers; only the wrapping differs.

FormatPEM labelHoldsDefined in
PKCS#8PRIVATE KEYAny private key, with its algorithm namedRFC 5208 and RFC 5958
SubjectPublicKeyInfo (SPKI)PUBLIC KEYAny public key, with its algorithm namedRFC 5280
PKCS#1 privateRSA PRIVATE KEYAn RSA private key onlyRFC 8017
PKCS#1 publicRSA PUBLIC KEYAn RSA public key onlyRFC 8017
JWK(JSON)Key parameters as Base64url fieldsRFC 7517 and RFC 7518

PKCS#8 and SPKI are the modern defaults that most libraries and tools read. PKCS#1 is the older RSA-specific form, which some software, including older OpenSSL-based tools, still expects.

The JWK and its kid

The public JWK has kty RSA, the modulus n and the exponent e, plus alg and use from your choice of algorithm. The kid is the RFC 7638 thumbprint: a SHA-256 hash of the key’s required members, so the same key always gets the same id.

Shape of the public JWK (placeholders)
{
  "kid": "<RFC 7638 thumbprint>",
  "use": "sig",
  "alg": "RS256",
  "kty": "RSA",
  "n": "<modulus, Base64url>",
  "e": "AQAB"
}

AQAB is 65537, the public exponent nearly every RSA key uses.

RS256, PS256 and RSA-OAEP-256

The algorithm choice sets the JWK’s alg and use and the Web Crypto algorithm the key is created for.

  • RS256: RSASSA-PKCS1-v1_5 signatures with SHA-256. The most widely supported JWT algorithm and Keycloak’s default for tokens.
  • PS256: RSA-PSS signatures with SHA-256. A more modern padding with a stronger security proof, supported by Keycloak and many libraries, though not all.
  • RSA-OAEP-256: encryption with OAEP padding and SHA-256, used for encrypted tokens (JWE) and encrypted SAML assertions.

Keep a key to one purpose. Use separate keys for signing and for encryption, which is also how Keycloak organizes realm keys.

How to generate a key pair

  1. Choose the key size. 2048 bits suits token signing; choose 3072 for a longer margin.
  2. Choose the algorithm the key is for.
  3. Choose PKCS#8 and SPKI unless the receiving software asks for PKCS#1.
  4. Copy the private key into a secrets manager or the target system’s key store.
  5. Copy the public key or the public JWK to wherever verifiers fetch it.

The private key appears on screen. Generate production keys on a trusted device, copy them straight to their destination and close the tab.

RSA keys in Keycloak

Every Keycloak realm has its own keys, listed under Realm settings, Keys. By default Keycloak generates them itself with the rsa-generated provider for signing and rsa-enc-generated for encryption. You rarely need to supply your own.

Bringing your own key

Add an rsa key provider under the Providers tab and paste the private key in PEM form, with the matching certificate if you have one. Keycloak generates a self-signed certificate if you do not supply one. Reasons to bring a key include moving a realm between servers without changing keys, or a policy that keys come from a central process.

Rotating keys without breaking sessions

Keycloak keys have a priority and can be active, passive or disabled. Active keys with the highest priority sign new tokens. Passive keys no longer sign but still verify. To rotate, add a new key with a higher priority, then make the old key passive. Delete the old key once every token and session signed with it has expired.

Applications that fetch keys from the realm’s JWKS endpoint, /realms/<realm>/protocol/openid-connect/certs, pick up the new key by its kid automatically.

Client keys

Clients that authenticate with a signed JWT (private_key_jwt) hold their own key pair. The client keeps the private key and Keycloak needs the public key, either pasted in the client’s Keys tab or fetched from a JWKS URL the client publishes.

Common mistakes

  • Sharing the private key with every service that verifies tokens. Verifiers need only the public key.
  • Mixing up PEM labels: giving software a PKCS#1 RSA PRIVATE KEY when it expects PKCS#8, or the reverse. Convert with this tool’s format choice or with openssl pkey.
  • Pinning a single key in applications instead of fetching the JWKS, which breaks every application on rotation.
  • Using keys under 2048 bits, which current guidance no longer accepts.
  • Storing private keys in source control or container images.

Security notes

Keys made here come from the browser’s Web Crypto implementation, the same code browsers use for their own cryptography. The key is created in memory and never sent anywhere.

Still, the most secure private key is one that never leaves the system that uses it. Where you can, let the identity provider generate its own keys, or create keys in a hardware security module or cloud key service.

NIST’s current guidance treats 112-bit strength, which 2048-bit RSA provides, as acceptable for now and plans to retire it in the coming years. New long-lived keys are a reasonable place to start using 3072 bits.

Checking an RSA key with OpenSSL

A few commands confirm that a key is what you think it is before it goes into production.

Useful OpenSSL commands for RSA keys
# Check the private key's internal consistency
openssl rsa -in private.pem -check -noout

# Print the size and parameters
openssl pkey -in private.pem -noout -text | head -1

# Confirm a public key matches the private key
openssl pkey -in private.pem -pubout | diff - public.pem && echo match

# Convert PKCS#8 to PKCS#1 and back
openssl pkey -in private.pem -traditional -out private-pkcs1.pem
openssl pkey -in private-pkcs1.pem -out private-pkcs8.pem

If a system rejects a key, the PEM label is the first thing to check: BEGIN PRIVATE KEY is PKCS#8 and BEGIN RSA PRIVATE KEY is PKCS#1. The bytes inside differ, so renaming the label alone does not convert a key.

Questions

Frequently asked questions

What RSA key size should I use in 2026?

2048 bits is the accepted minimum and is fine for token signing. Choose 3072 bits for keys that must stay in use for many years. 4096 bits works but is slower for little practical gain.

What is the difference between PKCS#1 and PKCS#8?

PKCS#1 (BEGIN RSA PRIVATE KEY) holds only RSA keys. PKCS#8 (BEGIN PRIVATE KEY) wraps any private key and names its algorithm. Most modern software prefers PKCS#8.

Is it safe to generate an RSA key in the browser?

Web Crypto uses the browser’s own vetted cryptography, and this page sends nothing. For production keys, generating them on the system that uses them avoids copying a private key at all.

What does AQAB mean in a JWK?

It is the Base64url encoding of the bytes 01 00 01, the number 65537. That is the public exponent used by nearly every RSA key.

Should I use RS256 or PS256?

RS256 is supported almost everywhere. PS256 has a stronger security proof and is supported by Keycloak and most modern libraries. Use PS256 when every verifier supports it.

How do I import my own RSA key into Keycloak?

In the realm’s Keys settings, add an rsa key provider and paste the private key in PEM form, with a certificate if you have one. Give it a higher priority than the existing key to make it the active signing key.

How do I get the public key from a private key?

With OpenSSL: openssl pkey -in private.pem -pubout. This tool shows both halves when it generates a pair.

Can I use the same RSA key for signing and encryption?

You can technically, but you should not. Separate keys limit the damage if one is misused or leaks, and some attacks exploit keys used both ways. Keycloak keeps signing and encryption keys apart for this reason.

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.