JustGenerator
Security & Keys 100% Client-Side Privacy

RSA Key Pair Generator

Create 2048-bit, 3072-bit, or 4096-bit RSA public and private keys in standard PEM (SPKI / PKCS#8) and JWK formats locally using the Web Crypto API.

Click Generate Key Pair to create keys locally in your browser. Public Exponent: 65537 (0x010001)

What Web Crypto exports here (SPKI, PKCS#8, and JWK)

When you click Generate Key Pair, your browser calls crypto.subtle.generateKey() with public exponent 65537 (0x010001) and exports the key pair in two formats without sending a single byte over the network:

  • PEM mode wraps the X.509 SubjectPublicKeyInfo (spki) bytes in -----BEGIN PUBLIC KEY----- and the PKCS#8 (pkcs8) private bytes in -----BEGIN PRIVATE KEY-----, line-wrapped at 64 Base64 characters.
  • JWK mode outputs the exact same key pair as RFC 7517 JSON Web Keys (kty: "RSA", modulus n, exponent e, and private CRT parameters) ready for OIDC /.well-known/jwks.json endpoints or Web Crypto importKey("jwk", ...).

Because both formats come from the same generated key object, switching the Output Format dropdown toggles instantly between PEM and JWK without regenerating new primes.

Choosing 2048-bit, 3072-bit, or 4096-bit keys

2048-bit RSA is the standard size for JWT RS256 signing, OAuth providers, and API authentication. Generating a 2048-bit pair in Chrome or Safari usually finishes in 50 to 250 milliseconds. Moving to 4096-bit keys takes noticeably longer to generate (often 1 to 4 seconds in a browser) and makes private-key signing roughly 4x to 6x slower on your server, while public-key verification stays fast. Pick 3072-bit or 4096-bit when a compliance policy requires it or when a root key needs to stay valid for a decade.

Why asymmetric keys beat shared secrets in multi-service apps

With symmetric JWT signing (HS256), every microservice that verifies a token also has to hold the signing secret, which means any compromised service can forge new admin tokens. With RSA (RS256), only your auth server holds private.pem. Every downstream API, edge worker, or third-party verifier only needs public.pem or the public JWK, which you can distribute openly without exposing signing privileges.

Handling PEM files in `.env` variables

Multi-line PEM keys often break simple .env parsers if you paste raw newlines directly. Two clean workarounds are replacing newlines with literal \n inside double quotes and restoring them with key.replace(/\\n/g, "\n") at startup, or Base64-encoding the entire PEM file using our Base64 Encoder & Decoder and decoding it in memory. For symmetric HMAC secrets instead of asymmetric keys, use our Random Token Generator.

Common questions

What is the difference between PKCS#8 and PKCS#1 for RSA private keys?

PKCS#1 (header: -----BEGIN RSA PRIVATE KEY-----) is an older format specific to RSA. PKCS#8 (header: -----BEGIN PRIVATE KEY-----) is the modern standard that wraps the key with an algorithm identifier so libraries can load RSA, ECDSA, or Ed25519 keys uniformly. Modern Web Crypto, Node.js, OpenSSL, and Java tools support PKCS#8 natively.

What is the difference between an RSA public key and private key?

RSA is asymmetric cryptography: the public key can be shared openly with anyone to verify digital signatures or encrypt data sent to you, while the private key must remain strictly secret on your server or device to sign tokens and decrypt incoming messages.

Should I choose a 2048-bit or 4096-bit RSA key size?

2048-bit RSA is the standard baseline for JWT signing (RS256), TLS certificates, and everyday API authentication because it offers strong security with fast signing performance. Choose 3072-bit or 4096-bit keys for long-lived root certificates, archival encryption, or compliance standards targeting protection past 2030.

What is PEM format for cryptographic keys?

PEM (Privacy-Enhanced Mail) is a text container format that Base64-encodes binary ASN.1 DER key structures, wraps them at 64 characters per line, and adds clear header and footer lines such as -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY-----. It is the standard format accepted by OpenSSL, Nginx, AWS, and Node.js.

How do I generate an RSA key pair with OpenSSL on my computer?

To generate a modern 2048-bit PKCS#8 private key in OpenSSL, run openssl genpkey -algorithm RSA -out private.pem -pkeyopt rsa_keygen_bits:2048. Then extract the matching public key with openssl rsa -in private.pem -pubout -out public.pem.

Are online RSA key generators safe to use?

Never use an online generator that creates RSA keys on a remote server, because the server could log your private key. This tool generates keys 100% locally inside your browser using the native Web Crypto API (crypto.subtle.generateKey) with zero network transmission. For high-security production infrastructure, generating keys directly on your air-gapped machine or HSM is still best practice.