RSA Key Pair Generator Online | 2048, 4096 Bit PEM JWK Export

Key Exchange
100% client-side. Processed locally in your browser using the Web Crypto API. Nothing is sent to any server.
⚠️ Critical Security: Use at least 2048-bit keys (3072+ recommended for long-term security). Store private keys securely — never share or commit them. For new projects, consider ECC (Curve25519) which offers equivalent security with much smaller keys and faster operations.

How It Works

What Is RSA Key Generation?

RSA (Rivest–Shamir–Adleman) is the most widely deployed public-key cryptosystem. An RSA key pair consists of a public key (shared openly, used for encryption and signature verification) and a private key (kept secret, used for decryption and signing). The security of RSA rests on the difficulty of factoring the product of two large prime numbers.

This tool generates RSA key pairs using the browser's native crypto.subtle.generateKey() API. Keys can be exported in PEM (SPKI/PKCS#8), DER, JWK, SSH public key, or PKCS#1 format — covering every major cryptographic ecosystem from OpenSSL and SSH to Java, Windows, and web APIs. Optional passphrase encryption produces an additional encrypted private key copy using OpenSSL traditional PEM format. All processing happens locally in your browser.

When to Use RSA Keys

  • TLS/SSL certificates — RSA is the default key type for most web server certificates
  • SSH authentication — RSA keys are the most widely supported SSH key type
  • JWT signing (RS256/PS256) — RSA signatures for JSON Web Tokens
  • Code signing — RSA is used for signing software packages and updates
  • Document signing — Digital signatures on PDFs and legal documents
  • When NOT to use — For new projects, prefer ECC (Curve25519/Ed25519) for smaller keys, faster operations, and quantum-readiness

Key Size Comparison

Key SizeSymmetric EquivalentGeneration SpeedRecommended UntilBest for
2048-bit~112-bitFast2030Most applications, TLS, SSH
3072-bit~128-bitModerate2031+Recommended for new deployments
4096-bit~140-bitSlower2031+Long-term security, CA root keys

Standards Compliance

  • RFC 8017 — PKCS #1: RSA Cryptography Specifications Version 2.2
  • NIST SP 800-56B — Key Pair Establishment using RSA
  • NIST FIPS 186-5 — Digital Signature Standard (DSS)
  • PKCS#8 / RFC 5958 — Private Key Information Syntax
  • Web Crypto API — W3C standard for browser-based RSA key generation

Last updated:

Code Examples

Generate RSA key pairs in multiple languages:

JavaScript — Web Crypto API (Browser)

// RSA 2048-bit key pair generation
const keyPair = await crypto.subtle.generateKey(
  {
    name: 'RSA-OAEP',
    modulusLength: 2048,
    publicExponent: new Uint8Array([1, 0, 1]),
    hash: 'SHA-256',
  },
  true,  // extractable
  ['encrypt', 'decrypt']
);

// Export public key as SPKI PEM
const pubBuf = await crypto.subtle.exportKey('spki', keyPair.publicKey);
const pubPem = '-----BEGIN PUBLIC KEY-----
' +
  btoa(String.fromCharCode(...new Uint8Array(pubBuf)))
    .match(/.{1,64}/g).join('
') +
  '
-----END PUBLIC KEY-----';
console.log(pubPem);

Python — PyCryptodome

from Crypto.PublicKey import RSA

# Generate 2048-bit RSA key pair
key = RSA.generate(2048)
with open('private.pem', 'wb') as f:
    f.write(key.export_key('PEM'))
with open('public.pem', 'wb') as f:
    f.write(key.publickey().export_key('PEM'))

Go — crypto/rsa

import (
    "crypto/rand"
    "crypto/rsa"
    "crypto/x509"
    "encoding/pem"
)

privateKey, _ := rsa.GenerateKey(rand.Reader, 2048)
privBytes := x509.MarshalPKCS1PrivateKey(privateKey)
privPem := pem.EncodeToMemory(&pem.Block{
    Type:  "RSA PRIVATE KEY",
    Bytes: privBytes,
})

Rust — rsa crate

use rsa::{RsaPrivateKey, RsaPublicKey};
use rsa::pkcs8::EncodePrivateKey;

let mut rng = rand::thread_rng();
let private_key = RsaPrivateKey::new(&mut rng, 2048)?;
let public_key = RsaPublicKey::from(&private_key);

// Export as PKCS#8 PEM
let pem = private_key.to_pkcs8_pem(LineEnding::LF)?;

Node.js — crypto module

const { generateKeyPairSync } = require('crypto');

const { publicKey, privateKey } = generateKeyPairSync('rsa', {
  modulusLength: 2048,
  publicKeyEncoding: { type: 'spki', format: 'pem' },
  privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
});

console.log('Public key:', publicKey);
console.log('Private key:', privateKey);

Common Pitfalls

⚠️ Using Keys Smaller Than 2048-bit: RSA keys below 2048 bits are considered insecure. NIST deprecated 1024-bit RSA in 2013. Use 2048-bit minimum, 3072+ for long-term security.
⚠️ Not Protecting Private Keys: Private keys must be stored securely — never commit them to version control, send them over unencrypted channels, or leave them in world-readable files. Use passphrase-encrypted copies for backup.
⚠️ Confusing PEM Formats: PKCS#8 ("BEGIN PRIVATE KEY") and PKCS#1 ("BEGIN RSA PRIVATE KEY") are different formats for the same key. Most modern tools prefer PKCS#8, but legacy systems may require PKCS#1.
⚠️ Not Verifying Public Key Fingerprints: When exchanging keys, always verify the SHA-256 fingerprint through a separate trusted channel. Without verification, a man-in-the-middle could substitute their own key.
⚠️ Using RSA for Encryption Directly: RSA can only encrypt small amounts of data (max ~190 bytes for RSA-2048 with OAEP). For larger data, use hybrid encryption: RSA encrypts a symmetric key, AES encrypts the data.

Security Notes

ℹ️ 2048-bit Is Sufficient for Most Use Cases: 4096-bit adds marginal security at the cost of slower operations. NIST considers 2048-bit secure through 2030.
ℹ️ Consider ECC for New Projects: Curve25519 offers equivalent security to RSA-3072 with much smaller keys (256-bit vs 3072-bit) and faster operations. Ed25519 is the modern default for SSH and signatures.
ℹ️ Batch Generation Uses Fresh Randomness: Each key pair in a batch is generated independently with fresh random primes. All pairs are cryptographically distinct.
ℹ️ Export Format Compatibility: PEM (SPKI/PKCS#8) works with OpenSSL, SSH, and most servers. JWK is best for JavaScript/JWT. SSH format is for OpenSSH/GitHub. PKCS#1 is for legacy systems.

Disclaimer

This tool is provided for educational and development purposes. Key generation security depends on the browser's cryptographic RNG implementation. For production systems, use well-audited key generation tools and follow NIST SP 800-56B guidelines.

Further Reading

Related Concepts

Related Tools

Need elliptic curve keys instead? Try the ECC Key Generator for Curve25519 or P-256 keys. To encrypt data with your generated RSA key pair, use the RSA Encrypt/Decrypt tool. For digital signatures with RSA, see the Digital Signature & Verify tool.

Frequently Asked Questions

What key size should I use?

2048-bit RSA provides security equivalent to 112-bit symmetric encryption and is sufficient for most applications through 2030. 4096-bit provides 128-bit equivalent security and is recommended for long-term protection. Larger keys are more secure but slower to generate and use.

What export formats are supported?

Multiple formats are supported: PEM (SPKI/PKCS#8, standard for OpenSSL/SSH), DER (raw binary as Base64, used in Java/Windows/X.509), JWK (JSON Web Key, RFC 7517), SSH public key format (ssh-rsa ...), and PKCS#1 private key format (BEGIN RSA PRIVATE KEY). You can also export an encrypted private key with passphrase protection.

What is the SSH public key format?

SSH format starts with "ssh-rsa" followed by a Base64-encoded binary structure containing the key type, public exponent, and modulus. This is the format used by OpenSSH, GitHub, GitLab, and most SSH servers for public key authentication. You can download or copy the SSH format directly from the results.

Can I generate multiple key pairs at once?

Yes. Use the Batch Quantity selector to generate 1, 2, 5, or 10 key pairs in a single operation. All pairs are generated independently with fresh random primes. The result view initially shows the last generated pair. Use the pair selector to view, copy, or download any pair individually.

How do I import and analyze a public key?

Expand the "Import & Analyze Public Key" panel and paste your public key in PEM, JWK, SSH, or Base64 DER format. Click "Parse Key" to view its metadata including key size, algorithm, public exponent, modulus, and SHA-256 fingerprint. This is useful for verifying a received key matches expectations.

Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.

More in Key Exchange

Learn More