RSA Key Generator
Create a new RSA public/private key pair in your browser with the WebCrypto API and copy or download it as PEM (PKCS#8 / SPKI or PKCS#1), JSON Web Key or OpenSSH. Keys are generated from your device's secure random generator and never leave the page.
How to use the RSA Key Generator
- Choose the key size. 2048 bits is the minimum for new keys; 3072 or 4096 bits give a longer security margin.
- Choose the usage: RSA-OAEP for encryption, RS256 for JWT and most signatures, or PS256 for RSA-PSS signatures.
- Press Generate key pair. 4096-bit keys can take a few seconds.
- Pick the output format: PEM PKCS#8, PEM PKCS#1, JWK or OpenSSH.
- Copy or download the public key to share and the private key to keep secret.
RSA key formats explained
| Format | Header / shape | Typical use |
|---|---|---|
| SPKI public key (X.509 SubjectPublicKeyInfo) | -----BEGIN PUBLIC KEY----- | OpenSSL, Java X509EncodedKeySpec, Node.js, Python, JWT verification |
| PKCS#8 private key | -----BEGIN PRIVATE KEY----- | OpenSSL 3 default, Java PKCS8EncodedKeySpec, Node.js, Go |
| PKCS#1 public key | -----BEGIN RSA PUBLIC KEY----- | Older OpenSSL and libraries that only handle RSA |
| PKCS#1 private key | -----BEGIN RSA PRIVATE KEY----- | Traditional OpenSSL format, SSH id_rsa, PHP, Ruby |
| JSON Web Key | {"kty":"RSA","n":"…","e":"AQAB"} | JWT/JOSE libraries, JWKS endpoints, OAuth and OpenID Connect |
| OpenSSH public key | ssh-rsa AAAAB3NzaC1yc2E… comment | ~/.ssh/authorized_keys, Git hosting, cloud servers |
All formats hold the same numbers: the modulus n = p × q (the product of two random primes of half the key size) and the public exponent e = 65537. The private key adds the private exponent d, where e × d ≡ 1 (mod λ(n)), plus p, q and three precomputed values that speed up decryption and signing through the Chinese remainder theorem.
Key size and security
| RSA modulus | Approx. symmetric security | Guidance (NIST SP 800-57) |
|---|---|---|
| 1024 bits | 80 bits | Disallowed, do not use |
| 2048 bits | 112 bits | Acceptable through 2030 |
| 3072 bits | 128 bits | Recommended beyond 2030 |
| 4096 bits | ~140 bits | Long-lived keys; slower private-key operations |
Useful OpenSSL commands
- Inspect a private key:
openssl rsa -in rsa-2048-private.pem -text -noout - Derive the public key:
openssl rsa -in rsa-2048-private.pem -pubout -out public.pem - Convert PKCS#8 to PKCS#1:
openssl rsa -in private.pem -traditional -out private-pkcs1.pem - Encrypt the private key with a passphrase:
openssl pkcs8 -topk8 -v2 aes-256-cbc -in private.pem -out private-enc.pem - Show the SSH fingerprint:
ssh-keygen -lf id_rsa.pub
Frequently asked questions
Is it safe to generate an RSA key in the browser?
The keys are created by the browser's built-in WebCrypto implementation, the same code that secures HTTPS, using the operating system's cryptographically secure random number generator. Nothing is sent to a server. For keys that protect high-value production systems, organisations often prefer generating keys on the server or in a hardware security module where they will be used.
Which key size should I choose?
NIST considers 2048-bit RSA acceptable until 2030, which is roughly 112-bit security. 3072 bits gives about 128-bit security and is recommended for keys used beyond 2030. 4096 bits is common for SSH and long-lived keys but is slower to sign and decrypt.
What is the difference between PKCS#8 and PKCS#1 PEM?
PKCS#1 (BEGIN RSA PRIVATE KEY / BEGIN RSA PUBLIC KEY) contains only the RSA numbers. PKCS#8 (BEGIN PRIVATE KEY) and SPKI (BEGIN PUBLIC KEY) wrap the same numbers with an algorithm identifier, so they can hold any key type. Most modern libraries prefer PKCS#8 and SPKI; older OpenSSL tools and some SSH software expect PKCS#1.
Can I use the key for SSH?
Yes. Put the OpenSSH public key line (ssh-rsa …) into ~/.ssh/authorized_keys on the server. Save the private key in PEM format as ~/.ssh/id_rsa with permissions 600; OpenSSH reads PKCS#1 and PKCS#8 PEM keys. You can add a passphrase afterwards with ssh-keygen -p -f ~/.ssh/id_rsa.
Is the private key encrypted with a password?
No, the private key is output unencrypted so that it works with every tool. Protect it by storing it securely, or add a passphrase locally, for example with openssl pkcs8 -topk8 -v2 aes-256-cbc -in key.pem -out key-encrypted.pem or ssh-keygen -p.
Why does the usage (OAEP, RS256, PS256) matter?
The RSA numbers are the same in every case, but WebCrypto binds each key to one algorithm, and the JWK output records it in the alg field. The PEM and OpenSSH formats do not store the usage, so a PEM key generated here can be used for any RSA operation in other software.
Is the generated key really random?
Yes. WebCrypto generates two large random primes with the system CSPRNG and refuses to export anything weaker. Each press of Generate gives a completely new key pair, and the page keeps no copy after you leave.