RSA key pair generator

Generate a new random RSA private and public pem certificate key pair.

loading RSA key pair generator
About this tool

What is an RSA key pair?

RSA is public-key cryptography: instead of one shared secret, you have two mathematically linked keys. The public key can be handed to anyone; the private key never leaves you. What one key does, only the other can undo. Encrypt with the public key and only the private key reads it; sign with the private key and anyone with the public key can verify the signature. That is what makes RSA useful for SSH logins, JWTs signed with RS256, TLS certificates, code signing and encrypting small secrets.

The key size, in bits, is the length of the modulus. 2048 bits is the usual minimum today and is estimated by NIST to give about 112 bits of security; 3072 bits gives about 128 and 4096 is common for long-lived keys. Bigger is slower to generate and to use, so 2048 or 3072 covers most needs. Keys under 2048 bits are considered weak, and this page warns you if you pick one.

Private and public keys are stored in several file formats, and that is where most confusion comes from. PEM is Base64 of the binary key between -----BEGIN ...----- lines, with a header that reveals the structure: PKCS#1 (BEGIN RSA PRIVATE KEY), PKCS#8 (BEGIN PRIVATE KEY) or SPKI for public keys (BEGIN PUBLIC KEY). OpenSSH has its own format for id_rsa and id_rsa.pub, and PuTTY uses .ppk. This RSA key pair generator creates the pair in your browser and writes it in the format you pick, with an optional passphrase that encrypts the private key, so the files are ready to download. Nothing is sent to a server, but for production keys generate them on the machine that will use them, with ssh-keygen or openssl. Since PEM is Base64 text, the Base64 tool can show what is inside.

How to generate an RSA key pair online

  1. Open the page: it generates a 2048-bit pair right away, in PKCS#1 for the private key and SPKI for the public key.
  2. Change Bits if needed. Allowed values are multiples of 8 from 1024 to 8192. A larger key takes longer, because the page searches for two large primes in background workers.
  3. Choose the Private key format: PEM PKCS#1, PEM PKCS#8, OpenSSH or PuTTY (.ppk). And the Public key format: PEM SPKI, PEM PKCS#1 or OpenSSH.
  4. Optionally type a passphrase to encrypt the private key, and a comment for OpenSSH and PuTTY keys, such as maria@laptop.
  5. Read the Public key and Private key boxes. They are rewritten when you change formats, without drawing a new pair.
  6. Copy each key or download it, with the suggested file name (id_rsa, id_rsa.pub, private_key.pem, public_key.pem, private_key.ppk).
  7. Press Generate a new key pair for a different one.

Examples

Which header means which format

The first line of the file tells you:

-----BEGIN RSA PRIVATE KEY-----      PKCS#1, private
-----BEGIN PRIVATE KEY-----          PKCS#8, private
-----BEGIN OPENSSH PRIVATE KEY-----  OpenSSH, private
-----BEGIN PUBLIC KEY-----           SPKI, public
-----BEGIN RSA PUBLIC KEY-----       PKCS#1, public

An OpenSSH public key is one line instead: ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB... followed by the comment. The AAAAB3NzaC1yc2E part is the Base64 of the text ssh-rsa with its length, and AAAADAQAB encodes the public exponent 65537.

Keys for SSH

Choose OpenSSH for both formats and a comment. Save the private key as ~/.ssh/id_rsa with chmod 600 ~/.ssh/id_rsa, and put the one-line public key in the authorized_keys of the server. Many tools refuse a private key with open permissions. For new SSH keys Ed25519 is often preferred, but RSA is supported everywhere.

Keys for JWT RS256

Choose PKCS#8 for the private key and SPKI for the public key, formats that many JWT libraries accept, with 2048 bits. Sign with the private key in your service and publish the public key so others can verify. You can test the pair with the JWT tool.

A passphrase-protected key

Typing a passphrase writes the private key encrypted. A PKCS#1 file then shows Proc-Type: 4,ENCRYPTED, and PKCS#8 becomes BEGIN ENCRYPTED PRIVATE KEY. Anyone who copies the file still needs the passphrase, so pick one the password strength analyser rates well.

Common errors and how to fix them

  • "Key size must be a multiple of 8 from 1024 to 8192, for example 2048.": type a valid size.
  • "Keys under 2048 bits are considered weak today.": a warning, not an error. Use 2048 or more for anything real.
  • The page seems stuck on large keys: 4096 bits and above can take a long time, since prime search is probabilistic. Wait, or use 2048 or 3072.
  • ssh says "invalid format" or "bad permissions": use the OpenSSH private key format for id_rsa, keep the line breaks, and set chmod 600.
  • A library asks for "BEGIN PRIVATE KEY" but got "BEGIN RSA PRIVATE KEY": switch the private key format between PKCS#1 and PKCS#8 here; no new pair is needed.

Frequently asked questions

Is it safe to generate a private key in a browser?

The keys are made locally with workers and nothing is uploaded. Still, a browser tab is a poorer place for a long-lived key than your own terminal, so use this for tests, learning and quick tasks, and generate production keys with openssl or ssh-keygen on the target machine.

Which key size should I use?

2048 bits is the usual minimum; 3072 is a sound choice for keys that must last years. Keys under 2048 bits are weak.

What is the difference between PKCS#1 and PKCS#8?

PKCS#1 is specific to RSA. PKCS#8 is a general container that names the algorithm, so it also works for other key types. Most modern libraries accept PKCS#8, and both hold the same key.

Should I encrypt data with RSA?

RSA handles only small messages. In practice it protects a symmetric key, and the data itself is encrypted with AES, as in the encrypt and decrypt tool.

Report a problem