PEM / JWK / JWKS

RSA & EC Key Pair Generator (PEM, JWK, JWKS)

Generate asymmetric RSA (RS256, PS256, RSA-OAEP) and ECDSA (P-256, P-384, P-521) key pairs locally inside your browser with WebCrypto. Export PKCS#8 private PEM, SPKI public PEM, private and public JWKs with RFC 7638 thumbprint kid values, and a public-only JWKS set.

How It Works

Asymmetric JWT signing replaces a shared symmetric secret with a mathematically linked private/public pair generated inside your browser via W3C WebCrypto crypto.subtle.generateKey. Your authorization server signs tokens using the private key while downstream microservices, mobile apps, or API gateways verify signatures using only the public SPKI PEM or JWKS endpoint.

For every generated key, the tool exports PKCS#8 PEM private keys and SPKI PEM public keys wrapped strictly at 64 characters per line, converts both halves into standard RFC 7517 JWK objects tagged with the matching JWA alg and use fields, and computes an RFC 7638 SHA-256 thumbprint over lexicographically sorted public members to assign a deterministic kid identifier.

Step-by-Step Guide & Real Example

Generate, inspect, and export production-formatted PEM, JWK, and public-only JWKS bundles directly in client memory in four steps.

1. Choose RSA or Elliptic Curve family

Select RSASSA-PKCS1-v1_5 (RS256/384/512), RSA-PSS (PS256/384/512), RSA-OAEP for JWE key encryption, or ECDSA for compact elliptic-curve signatures.

2. Configure bit strength or curve

Pick 2048, 3072, or 4096 modulus bits for RSA alongside SHA-256/384/512, or pick NIST P-256 (ES256), P-384 (ES384), or P-521 (ES512) for ECDSA.

3. Generate and inspect the RFC 7638 kid

WebCrypto runs prime/curve key generation asynchronously inside browser memory and labels the resulting JWK and public JWKS with the SHA-256 JWK thumbprint.

4. Export PEM, JWK, JWKS, or OpenSSL CLI

Copy or download the PKCS#8 private key for your vault, publish the public JWKS (never containing private parameters) to your verifiers, or run the equivalent OpenSSL command offline.

Worked Example: RFC 7638 Section 3.1 JWK Thumbprint

Public RSA JWK Members (Sorted Order: e, kty, n):{"e":"AQAB","kty":"RSA","n":"0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx..."}
Deterministic SHA-256 Base64URL kid Thumbprint:kid: "NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs"

Because RFC 7638 hashes only required public parameters in canonical key order without whitespace, any compliant server recomputes the exact same key ID.

Common Mistakes & Security Notes

Publishing private JWK parameters inside JWKS endpoints

A JWKS served at /.well-known/jwks.json must contain ONLY public fields (n, e for RSA; crv, x, y for EC). Exposing d, p, or q lets attackers forge every token.

Confusing PKCS#1 and PKCS#8 PEM headers

WebCrypto and modern Node.js/Java runtimes export PKCS#8 (BEGIN PRIVATE KEY) and SPKI (BEGIN PUBLIC KEY). Legacy libraries expecting PKCS#1 should be upgraded or explicitly configured.

Generating high-security root keys solely in a web tab

Although keys here never leave browser memory, production root and long-lived identity keys belong in offline hardware HSMs, KMS services (AWS KMS, Vault), or audited CLI terminals.

Omitting "kid" headers during key rotation

Rotating signing keys without unique kid identifiers forces verifiers to trial-decrypt signatures across every active key in your JWKS.

PEM (PKCS#8 / SPKI) vs JWK vs JWKS

FormatScopeTypical Header / FieldsBest Integration Pattern
PKCS#8 PEMPrivate Signing KeyBEGIN PRIVATE KEY (ASN.1 DER)Environment secrets & container mounts
SPKI PEMPublic Verify KeyBEGIN PUBLIC KEY (SubjectPublicKeyInfo)Nginx, Envoy, or static microservice configs
JWK (JSON Web Key)Single Key JSONkty, alg, use, kid, n/e or x/y (+d if private)WebCrypto importKey & RFC 7517 SDKs
JWKS (Key Set)Public Rotation Set{ "keys": [ publicJwk... ] }OAuth 2.0 / OIDC /.well-known/jwks.json

Code Snippets (Node.js, Python, Java)

Generate equivalent PEM keys and RFC 7638 thumbprints natively inside your application build pipeline or server runtime:

Node.js (TypeScript)
import { generateKeyPairSync, createHash } from 'node:crypto';

const { publicKey, privateKey } = generateKeyPairSync('rsa', {
  modulusLength: 2048,
  publicKeyEncoding: { type: 'spki', format: 'pem' },
  privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
});
const jwk = publicKey.export({ format: 'jwk' });
const kid = createHash('sha256')
  .update(JSON.stringify({ e: jwk.e, kty: 'RSA', n: jwk.n }))
  .digest('base64url');
Python
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import serialization

priv = ec.generate_private_key(ec.SECP256R1())
priv_pem = priv.private_bytes(
    serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8, serialization.NoEncryption()
)
pub_pem = priv.public_key().public_bytes(
    serialization.Encoding.PEM, serialization.PublicFormat.SubjectPublicKeyInfo
)
Java
KeyPairGenerator gen = KeyPairGenerator.getInstance("EC");
gen.initialize(new ECGenParameterSpec("secp256r1"));
KeyPair kp = gen.generateKeyPair();
String spkiB64 = Base64.getMimeEncoder(64, new byte[]{'\n'})
    .encodeToString(kp.getPublic().getEncoded());

Frequently Asked Questions

Should I choose RSA 2048 or ECDSA P-256 for JWT signing?

ECDSA P-256 (ES256) creates much smaller keys and signatures with fast verification and roughly 128-bit security strength. Choose RSA 2048+ (RS256) when integrating older enterprise clients that lack ECDSA support.

Why does generating RSA 4096 take noticeably longer than P-256?

RSA key generation must search for and probabilistically verify two 2048-bit prime numbers, which takes noticeably more CPU cycles in the browser than sampling a single 256-bit ECDSA scalar.

Does the exported Public JWKS ever include private key material?

Never. The JWKS tab strips all private parameters (d, p, q, dp, dq, qi, oth) and renders strictly public key objects safe to expose over HTTPS.

How is the kid thumbprint calculated?

This generator implements RFC 7638: it serializes only the required public JWK fields in strict alphabetical key order with zero whitespace, hashes the UTF-8 bytes with SHA-256, and encodes the digest as Base64URL.

What is RSA-OAEP used for compared to RSASSA-PKCS1-v1_5 and RSA-PSS?

RSASSA-PKCS1-v1_5 (RS256) and RSA-PSS (PS256) sign JWS tokens (use: sig). RSA-OAEP encrypts content encryption keys inside encrypted JWE tokens (use: enc).

Should I use keys generated in a browser directly as production root keys?

While keys generated here stay 100% local in browser memory and are fine for development, testing, or staging, generate long-term production identity keys offline or inside a dedicated KMS/HSM.

About the author

Avada Labs builds free developer tools, including this site, with six years of experience in web development and online tools. Projects and source code are on GitHub.

RSA & EC Key Pair Generator – PEM, JWK & JWKS Online