Skip to content

RSA Key Pair Generator

Generate RSA public and private key pairs in PEM format using the Web Crypto API in your browser.

RSA Key Pair Generator tool

Loading...

Example

Input: Key Size 2048-bit, then Generate Key Pair

Result: A new public key (SPKI PEM, starting -----BEGIN PUBLIC KEY-----) and matching private key (PKCS8 PEM, starting -----BEGIN PRIVATE KEY-----)

The Web Crypto API generates a fresh 2048-bit key pair in your browser each time. Share only the public key and keep the private key secret.

  1. Choose the key size: 2048-bit for standard use or 4096-bit for a larger margin.
  2. Click Generate Key Pair.
  3. Wait a moment while your browser creates the keys.
  4. Copy the public key (PEM) to share for encryption or signature checks.
  5. Copy the private key (PEM) and store it safely. Never share it.
  6. Save each key in its own file, for example public.pem and private.pem.

Choosing an RSA Key Size: 2048 or 4096 Bits

This generator creates a matching RSA public and private key in your browser and gives you both as PEM text. Choose 2048-bit for most uses today, or 4096-bit for a larger safety margin. The private key is never sent anywhere.

RSA is a form of public-key cryptography. You share the public key freely, and anyone can use it to encrypt data for you or to check your signatures. Only the private key can decrypt that data or create those signatures. NIST rates a 2048-bit key at about 112 bits of security, which it accepts through 2030, and advises 3072 bits or more after that. A 4096-bit key is slower to create and to use, and it can take a few seconds to generate.

The public key comes out in SPKI format (BEGIN PUBLIC KEY) and the private key in PKCS#8 format (BEGIN PRIVATE KEY), with the usual public exponent of 65537. OpenSSL, Node.js, Python and most JWT libraries read these directly. The browser creates the key for RSA-OAEP encryption, but the exported key is standard RSA, so libraries can also use it to sign, for example RS256 tokens.

Two cautions. First, the private key has no passphrase. Save it with strict file permissions, or encrypt it with a command such as openssl pkcs8 -topk8 -v2 aes-256-cbc. Second, SSH needs a different format. Convert the public key with ssh-keygen -i -m PKCS8 -f public.pem, or create SSH keys with ssh-keygen itself. To protect a message with a shared password instead of keys, use Text Encryption and Decryption, and to inspect tokens you sign, try the JWT Decoder.

Sources

Frequently Asked Questions

For most uses, 2048-bit is enough today and is faster to generate and use. Pick 4096-bit for keys that must stay safe well past 2030, such as a long-lived signing key or a root certificate. Anything below 2048 bits is no longer considered safe. If your system supports it, elliptic curve keys give similar security with much smaller keys.
The key math is sound: the Web Crypto API uses a cryptographically secure random source. The bigger risk is handling. Browser extensions, clipboard managers and shared computers can expose a private key. For production keys, generating them on the server that will use them, or in a hardware security module, keeps the private key from ever being copied.
Save it to a file only you can read, such as chmod 600 private.pem on Linux or macOS. Better, encrypt it with a passphrase using openssl pkcs8 -topk8 -in private.pem -out private-enc.pem -v2 aes-256-cbc. Never commit it to a code repository or paste it into chat. Only the public key should be shared.
Yes, after converting the public key. Run ssh-keygen -i -m PKCS8 -f public.pem to get the one-line ssh-rsa format for authorized_keys. For new SSH keys, many admins use ssh-keygen -t ed25519, which makes shorter, faster keys.
Yes. Use the private key with the RS256 algorithm (RSA with SHA-256) in your JWT library, and give the public key to the services that verify tokens. Most libraries in Node.js, Python, Java and Go accept these PEM files as they are. Keep the private key on the server that issues tokens only.

Related Tools

Text Encryption and Decryption

Encrypt and decrypt text using AES-256 encryption entirely in your browser. No data sent to servers.

Security and Encryption

JWT Decoder

Decode JSON Web Tokens to inspect header, payload, and signature without needing the secret key.

Developer Tools

Password Generator

Generate strong, secure passwords with customizable length, character types, and multi-word passphrases.

Security and Encryption

Token Generator

Generate random tokens and strings in hex, alphanumeric, URL-safe, and custom character set formats.

Security and Encryption

Bcrypt Hash Generator and Verifier

Generate bcrypt hashes with configurable rounds and verify passwords against existing bcrypt hashes.

Security and Encryption

BIP39 Mnemonic Generator

Generate BIP39 mnemonic seed phrases for cryptocurrency wallets in 12, 15, 18, 21, or 24 words.

Security and Encryption