RSA Key Pair Generator
Generate RSA public and private key pairs for asymmetric encryption, digital signatures, and secure key exchange. Create industry-standard RSA keys compatible with OpenSSL, SSH, TLS/SSL, and legacy cryptographic applications.
RSA-OAEP with SHA-256 · PEM output
Generated key pairRSA-4096
Generating your RSA key pair…
What is RSA Encryption?
RSA (Rivest-Shamir-Adleman) is one of the most widely used public-key cryptosystems for secure data transmission. Named after its inventors Ron Rivest, Adi Shamir, and Leonard Adleman, RSA enables secure communication without requiring a shared secret key.
Asymmetric Encryption
Uses a pair of mathematically related keys: one public (shareable) and one private (secret). Data encrypted with one key can only be decrypted with the other.
Digital Signatures
Sign documents and messages with your private key to prove authenticity and integrity. Others can verify signatures using your public key.
Key Exchange
Securely share symmetric encryption keys over insecure channels. Commonly used in TLS/SSL handshakes and secure communication protocols.
Common Use Cases
Encryption
Encrypt sensitive data with the public key. Only the private key holder can decrypt it.
Digital Signatures
Sign documents or code with your private key. Anyone can verify with your public key.
JWT Signing (RS256)
Sign JWTs with RSA for scenarios where multiple parties need to verify tokens.
Key Exchange
Securely exchange symmetric keys by encrypting them with the recipient’s public key.
RSA Key Size Comparison
| Key Size | Security Level | Performance | Use Cases |
|---|---|---|---|
| 1024 bits | Deprecated | Very Fast | Legacy systems only |
| 2048 bits | Legacy (~112-bit classical) | Fast | Legacy systems only; actively being phased out |
| 3072 bits | Transitional (~128-bit classical) | Moderate | CNSA 1.0 classical floor during PQC transition |
| 4096 bits | Strong Classical (~140-bit) | Slower | Best classical fallback; still vulnerable to quantum attacks |
| ML-KEM-1024 / ML-DSA-87 | Post-Quantum (CNSA 2.0) | Very Fast | Target replacement for new systems — ML-KEM & ML-DSA |
Implementation Examples
Node.js Encryption
const crypto = require('crypto');
const fs = require('fs');
// Load RSA keys
const publicKey = fs.readFileSync('public.pem', 'utf8');
const privateKey = fs.readFileSync('private.pem', 'utf8');
// Encrypt data
function encryptRSA(data, publicKey) {
return crypto.publicEncrypt({
key: publicKey,
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
oaepHash: 'sha256',
}, Buffer.from(data));
}
// Decrypt data
function decryptRSA(encryptedData, privateKey) {
return crypto.privateDecrypt({
key: privateKey,
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
oaepHash: 'sha256',
}, encryptedData);
}
const message = "Hello, RSA!";
const encrypted = encryptRSA(message, publicKey);
const decrypted = decryptRSA(encrypted, privateKey);
console.log('Decrypted:', decrypted.toString());Python Digital Signatures
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import rsa, padding
# Generate key pair
private_key = rsa.generate_private_key(
public_exponent=65537, key_size=2048
)
public_key = private_key.public_key()
# Sign data
def sign_data(data, private_key):
return private_key.sign(
data.encode('utf-8'),
padding.PSS(
mgf=padding.MGF1(hashes.SHA256()),
salt_length=padding.PSS.MAX_LENGTH
),
hashes.SHA256()
)
# Verify signature
def verify_signature(data, signature, public_key):
try:
public_key.verify(
signature, data.encode('utf-8'),
padding.PSS(
mgf=padding.MGF1(hashes.SHA256()),
salt_length=padding.PSS.MAX_LENGTH
), hashes.SHA256()
)
return True
except:
return False
message = "Important document"
signature = sign_data(message, private_key)
is_valid = verify_signature(message, signature, public_key)
print(f"Valid signature: {is_valid}")RSA Applications
Web Security
- TLS/SSL Certificates: HTTPS connections
- JWT Signing: RS256 algorithm
- OAuth: API authentication
- Code Signing: Software verification
Communication
- Email Encryption: S/MIME
- PGP/GPG: File encryption
- VPN: IPsec configurations
- Messaging: End-to-end encryption
Web Push notifications use ECDSA P-256 key pairs rather than RSA — generate VAPID keys for those instead.
Generate Locally (Recommended)
For production use, generate RSA keys locally:
Generate 4096-bit RSA private key (OpenSSL)
openssl genrsa -out private.pem 4096Extract public key
openssl rsa -in private.pem -pubout -out public.pemGenerate with AES-256 passphrase protection
openssl genrsa -aes256 -out private.pem 4096Post-quantum alternative (OpenSSL 3.5+ · CNSA 2.0)
openssl genpkey -algorithm ML-KEM-1024 -out mlkem1024.pemHow to use this RSA key generator
Post-quantum & production notice
RSA is a classical public-key algorithm vulnerable to future quantum attacks (Shor's algorithm) and harvest-now, decrypt-later collection. Following the NSA's Dec 2026 CNSA 2.0 advisory, use RSA-3072/4096 only as a transitional fallback—for new key exchange or signing systems, use ML-KEM (FIPS 203) or ML-DSA (FIPS 204).
While these keys are generated locally in your browser and never transmitted, for production use generate keys on your own machine with OpenSSL and never share your private key.
Read the post-quantum cryptography guide →