RSA Key Pair Generator Online | 2048, 4096 Bit PEM JWK Export
Key Exchange 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 Size | Symmetric Equivalent | Generation Speed | Recommended Until | Best for |
|---|---|---|---|---|
| 2048-bit | ~112-bit | Fast | 2030 | Most applications, TLS, SSH |
| 3072-bit | ~128-bit | Moderate | 2031+ | Recommended for new deployments |
| 4096-bit | ~140-bit | Slower | 2031+ | 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
Security Notes
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
- RFC 8017 — PKCS #1: RSA Cryptography Specifications
- NIST SP 800-56B — Key Pair Establishment using RSA
- NIST FIPS 186-5 — Digital Signature Standard
- RFC 7517 — JSON Web Key (JWK)
Related Concepts
- ECC Key Generator — Modern alternative with smaller keys and faster operations
- RSA Encrypt/Decrypt — Encrypt data using your generated RSA keys
- Digital Signature Verify — Create and verify RSA signatures
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
ECC / ECDSA Key Generator
Generate ECC key pairs on P-256, P-384, P-521, and secp256k1 online. Export PEM/JWK/hex, sign and verify ECDSA, derive ECDH secrets.
ECDH Key Exchange
Perform ECDH key exchange online across P-256, P-384, P-521, secp256k1, and X25519. Compute shared secrets, derive symmetric keys.
ML-KEM Key Encapsulation
Generate ML-KEM (FIPS 203) post-quantum key pairs online. Encapsulation and decapsulation with ML-KEM-512/768/1024, hex and Base64 output.