RSA key pair generator
Generate an RSA public and private key pair in your browser. Export it as PEM, PKCS#1, OpenSSH or JWK, protect it with a passphrase, and try it by signing and encrypting a message. Nothing leaves this page.
Key size
The usual default, accepted everywhere. NIST deems it safe until 2030. Generated in your browser with Web Crypto: the keys never leave this page.
Private key
BEGIN PRIVATE KEY: the modern format, read by OpenSSL, Node.js, Java, Go and jose. Add a passphrase to encrypt it.
…
Public key
BEGIN PUBLIC KEY (SPKI): what OpenSSL, Node.js, jose and most libraries read.
…
Key details
Generating your first key…
Randomart
What is an RSA key pair?
RSA is a public key algorithm: it uses two keys that only work together. The private key stays with you, and signs or decrypts. The public key can be shared with anyone, and verifies or encrypts. What one key does, only the other can undo.
Generating a pair means finding two large random primes, p and q. Their product n and the exponent e = 65537 form the public key. The private key adds the exponent d, which is easy to compute when you know p and q, and practically impossible from n alone: factoring a 2048-bit number is out of reach of every known computer.
Which key size to choose
2048 bits is the default of OpenSSL, ssh-keygen and most cloud providers, equivalent to 112 bits of security. NIST deems it safe until 2030.
3072 bits gives 128 bits of security, like AES-128, and is what NIST recommends past 2030. 4096 bits adds margin for keys that live long, like certificate authorities, at the cost of signing about 7 times slower than 2048 bits.
1024 bits is no longer safe: keep it for tests and for systems that accept nothing else.
PEM, PKCS#1, PKCS#8, OpenSSH and JWK
The same key can be written several ways, and every library expects its own:
BEGIN PRIVATE KEYis PKCS#8, the modern format of private keys, read by Node.js, Java, Go, Python and OpenSSL 3.BEGIN ENCRYPTED PRIVATE KEYis the same, encrypted with a passphrase.BEGIN RSA PRIVATE KEYis PKCS#1, the traditional OpenSSL format, andBEGIN RSA PUBLIC KEYits public counterpart.BEGIN PUBLIC KEYis SPKI(SubjectPublicKeyInfo), the format of public keys most tools mean by "PEM public key".ssh-rsa AAAA…is the OpenSSH public key, one line forauthorized_keys.- JWK is the JSON form of RFC 7517, used by JWT libraries and published in JWKS endpoints.
Generate an RSA key pair with OpenSSL
To create the same keys from a terminal, with OpenSSL 3:
# Private key, PKCS#8 openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out private.pem # Public key, SPKI openssl pkey -in private.pem -pubout -out public.pem # Encrypt the private key with a passphrase openssl pkey -in private.pem -aes-256-cbc -out encrypted.pem # Convert to PKCS#1 openssl rsa -in private.pem -traditional -out private-rsa.pem
For SSH, ssh-keygen -t rsa -b 4096 writes the private key to ~/.ssh/id_rsa and the public key to ~/.ssh/id_rsa.pub. In Node.js, crypto.generateKeyPairSync("rsa", { modulusLength: 2048 }) does the same.
RSA or Ed25519?
RSA is supported everywhere, from 20-year-old Java to hardware tokens, which makes it the safe choice when you don't control the other side. For new systems, Ed25519 is faster, with 32-byte keys and 64-byte signatures instead of 256 bytes for RSA 2048, and has fewer ways to be used wrong.
That's why LicenseManager signs its offline license tokens with Ed25519: your app verifies them with the public key, and nobody can forge one without the private key, which never leaves our servers. Paste a token in the JWT debugger to see how it's built.
Keep the private key private
Anyone holding the private key can sign as you or read what was encrypted for you. Store it in a secret manager or an environment variable, never in a Git repository or in an app you ship to customers. Encrypt it with a passphrase when it sits in a file, and restrict the file with chmod 600.
Only the public key goes in your app. If you sign licenses, your app holds the public key to check them: shipping the private key would let anyone create licenses.
Questions
With this generator, yes: the keys are generated by the Web Crypto API of your browser, on your device, and never sent anywhere. The page makes no request when you generate a key, and keeps nothing once you close it. For keys guarding production systems, you can also disconnect from the network before generating, or use OpenSSL with the commands on this page.
2048 bits is the usual default and NIST considers it safe until 2030. Choose 3072 bits for keys that must stay safe past 2030, and 4096 bits if you want extra margin and don't mind slower signing. 1024-bit keys can be broken by well-funded attackers and are only for tests and legacy systems.
PKCS#1 (BEGIN RSA PRIVATE KEY) only holds RSA keys. PKCS#8 (BEGIN PRIVATE KEY) wraps any kind of key with an identifier of its algorithm, and can be encrypted with a passphrase (BEGIN ENCRYPTED PRIVATE KEY). The numbers inside are the same: most modern libraries prefer PKCS#8, older ones and some SSH tools expect PKCS#1.
Yes. Copy the OpenSSH public key into ~/.ssh/authorized_keys or into the SSH keys of GitHub or GitLab, and save the PKCS#1 private key as ~/.ssh/id_rsa with chmod 600. For new SSH keys, Ed25519 is shorter and faster: ssh-keygen -t ed25519.
It's a standard PKCS#8 key encrypted with AES-256-CBC, the key being derived from your passphrase with PBKDF2-HMAC-SHA256. OpenSSL, Node.js, Python's cryptography and Java read it given the passphrase, for instance: openssl pkey -in private.pem -out decrypted.pem.
No: RSA-OAEP encrypts at most a few hundred bytes, 190 with a 2048-bit key. To encrypt a file, encrypt it with a random AES key, and encrypt that AES key with RSA. This is what TLS, PGP and age-like tools do.
Yes: sign the license data with the private key kept on your server, and verify the signature in your app with the public key. Anyone can read a signed license, nobody can forge one. LicenseManager does this with Ed25519, whose signatures are 64 bytes instead of 256.
More free tools
Signed licenses, without managing keys
LicenseManager signs a license for every Stripe purchase and your app verifies it offline with a public key. No key pair to generate, rotate or hide.