How to generate RSA keys
August 21, 2026 · 13 min read
RSA key pairs power RS256 JWT signing, TLS certificates, and legacy integrations. The private key signs; the public key verifies. Modern tutorials favor ECDSA for size and performance, but RSA remains ubiquitous in enterprise identity providers and JWKS endpoints.
When you need RSA
Use RSA when your identity provider issues RS256 tokens, when partners expect PEM public keys, or when documentation still references 2048-bit RSA. For greenfield internal microservices, consider EdDSA/ECDSA if all verifiers support it.
Key sizes
2048-bit RSA is the common minimum; 3072 or 4096 for long-lived roots. Shorter keys are obsolete. Generating in the browser for experiments is fine; production keys often come from HSM or cloud KMS.
Generate a key pair
The RSA keypair generator creates a pair in your browser using Web Crypto, exports PEM for private and public keys, and lets you copy material into local env files - never commit private keys to git.
-----BEGIN PUBLIC KEY-----
... base64 DER ...
-----END PUBLIC KEY-----
RSA and JWT RS256
Sign JWTs with the private key; resource servers fetch the public key from JWKS or config. Header alg must be RS256. Test round-trip with the JWT generator and decode with the JWT decoder using only the public key for inspection.
Key hygiene
- Store private keys in secrets managers, not Slack or tickets.
- Rotate on compromise and on schedule for long-lived signing keys.
- Publish JWKS with kid so verifiers pick the right key during rotation.
FAQ
- Is browser RSA generation secure?
- Web Crypto is appropriate for dev and learning. Production signing often uses HSM/KMS with audit and rotation policies.
- RS256 vs HS256?
- RS256 uses asymmetric keys - verifiers only need the public key. HS256 uses one shared secret - simpler but must stay secret everywhere.
Related: RS256 vs HS256 · RSA keypair generator