Generate an RSA Key Pair — Free 2048/4096-bit PEM Generator
Pick a key size — 2048-bit or 4096-bit — then click Generate Key Pair, and the RSA Key Pair Generator hands you back a matching public key and private key in standard PEM format. It all runs on your browser's native Web Crypto API, so your private key is generated and shown to you locally — never transmitted anywhere.
Every time you secure a connection, sign a JWT, or authenticate over SSH, an RSA key pair is working silently in the background. This RSA key pair generator gives you cryptographically secure public and private keys instantly — generated entirely in your browser so your key material never leaves your device. Whether you are a developer integrating public-key encryption into an application, a student exploring computer science concepts, or a systems engineer setting up a secure tunnel, understanding what your generated keys do — and how to handle them safely — is the difference between robust data security and a critical vulnerability.
What Is an RSA Key Generator Producing?
RSA, short for Rivest–Shamir–Adleman (rivest-shamir-adleman), is the most widely deployed public-key cipher system in internet protection. At its core, the method relies on two mathematically related keys — a shareable key and a secret key — whose relationship is easy to compute in one direction but computationally infeasible to reverse without the other half. That one-way mathematical relationship is what gives RSA its strength: even with massive computing power, deriving one key from the other at an adequate key length is not practically achievable.
The RSA method depends on the difficulty of factoring the product of two very large prime numbers. The rsa modulus — that product — forms the foundation of both keys. Its bit length, known as the modulus size, directly determines cipher strength and is what you select before you generate keys.
How Asymmetric Encryption Works With a Private Key
Asymmetric encoding uses a pair of mathematically related keys rather than a single shared secret. Any message ciphered with one key can only be deciphered with the other, which eliminates the need to securely exchange a shared secret before communication begins. This approach is ideal for protecting data across a large number of parties because each person only needs a single key pair — publish the public component freely and keep the secret half locked away. RSA underpins the secure browser connections your device makes every day, as well as transport-layer handshakes, secure shell login, and dozens of other protected communication protocols.
The dual-key method also scales elegantly: a sender can protect sensitive content with the recipient's shareable key, and only the secret-key holder can recover it — a process known as data decryption. Conversely, a signer can produce a digital signature with their secret key, and anyone holding the corresponding shareable key can perform validity checking to confirm authenticity. This dual capability — ciphering and attesting — makes RSA the backbone of public key infrastructure (PKI) and modern data protection.
Public Key Roles vs. Private Key Roles
Understanding which key does what prevents costly configuration mistakes:
- Public key — freely distributable; used to protect data or verify signatures. Share it with anyone who needs to send you secured messages or confirm your identity. Distributing your shareable key carries no risk.
- Private key — must remain secret at all times; used to recover received ciphertext or to sign documents and messages. Safeguarding your secret key is paramount: if it is compromised, every message secured for you and every signature you have produced is at risk.
The RSA relationship between the two keys is strictly one-directional for protective purposes. You can freely derive the shareable key from the secret key (as the openssl rsa command does), but you cannot derive the secret key from the shareable key — that is precisely what makes the cipher system robust. Never share your secret key or transmit it over a network.
Using This Free RSA Key Pair Generator Online
This free RSA key pair generator is an interactive resource designed for both rapid prototyping and learning. All generation happens through the browser's built-in Web Crypto API, which provides cryptographically secure random number generation. Because the tool is 100% client-side, your generated secret key and shareable key output never leave your device — no registration required, no data stored on any server. It is free forever and produces instant results for 2048-bit keys.
Select Key Size — Bit Length Selection
Your first decision is key length selection. The tool offers three production-grade sizes:
- 2048-bit (Recommended) — the current standard for most web and application use. Equivalent to approximately 112-bit equivalent symmetric protection; adequate until approximately 2030 per the standards body SP 800-131A guidance.
- 3072-bit — a middle tier offering stronger long-term protection with moderate performance overhead.
- 4096-bit (High Security) — maximum protection for root certificate authorities, long-term archival, and high-sensitivity environments. Slower to generate and to use in handshakes.
Historical note: 1024 bits and 512 bits are deprecated. At 1024 bits, the key is no longer considered safe; at 512 bits, it is trivially broken by modern hardware. Always select 2048 bits or above for any real-world application.
Choose Output Format — PEM, PKCS#1, PKCS#8
After selecting bit length, Choose output structure to match your target environment. The tool supports PEM (Privacy Enhanced Mail) wrapping for all output. Within PEM, you can select the internal layout:
- PKCS#1 (Public-Key Cryptography Standards #1) — RSA-specific key structures. The PEM block begins with
-----BEGIN RSA PRIVATE KEY-----. Widely supported by OpenSSL and legacy systems; suited for RSA-only workflows. - PKCS#8 (Public-Key Cryptography Standards #8) — a general private-key container that can hold keys from multiple cipher types, not just RSA. The PEM container begins with
-----BEGIN PRIVATE KEY-----. Preferred by modern Java, Python, and many current cipher applications.
Both layouts use Base64 conversion wrapped in a recognisable header and footer — a textual container around the encoded key data. The choice between them depends on your protocol requirements and the key import requirements of the receiving system. When in doubt, PKCS#8 is the more widely compatible structure for modern stacks.
Generate & Copy Keys — Key Pair Creation
Click Generate key pair to produce both keys. For 2048 bits, generation completes in well under a second; for 4096-bit keys, expect a few seconds of processing depending on your device. Once generated, the shareable key output and secret key appear in separate text areas. Use the Copy keys buttons to capture each PEM block — including the full header and footer lines — and paste them directly into your application server, configuration file, or vault.
WARNING: Copy and store your secret key immediately after generation. This tool does not retain keys between sessions. If you navigate away without saving, you must generate a new key pair.
RSA Key Size Comparison — Free RSA Key Pair Generator Reference Table
Choosing the right key length is a balance between cipher strength, performance, and compatibility. The key length comparison table below summarises the trade-offs for each supported bit length, reflecting industry and regulatory recommendations:
| Key Size | Security Level | Performance | Use Cases |
|---|---|---|---|
| 1024-bit | Deprecated (below 80-bit equivalent protection) | Very Fast | Legacy systems only — do not use for new deployments |
| 2048-bit (Recommended) | Current standard (~112-bit equivalent protection); adequate until 2030 | Fast | Web browsers, transport-layer credentials, JWT attesting, general API identity verification |
| 3072-bit | 140-bit protection — strong long-term coverage | Moderate | High-value services, post-2030 planning, intermediate CAs |
| 4096-bit (High Security) | Robust protection (~140-bit and above) | Slower | Root CAs, long-term archival, government and financial infrastructure |
PEM, PKCS#1, and PKCS#8 Format Details
PEM (Privacy Enhanced Mail) is a representation standard that encodes binary key data in Base64 and wraps it between human-readable header and footer lines (for example, -----BEGIN PRIVATE KEY-----). PEM output is the de-facto standard for OpenSSL-compatible and secure-shell-compatible toolchains. Most transport-layer credentials and identity documents are distributed in this wrapped layout.
PKCS#1 defines RSA-specific key structures — the container carries raw RSA modulus, exponents, and prime factors directly. It has historical compatibility advantages and is the default layout produced by openssl genrsa. PKCS#8 wraps the same RSA key bytes in a general private-key container that also records the method identifier, making it more portable across public-key standards. Modern Java keystores, Python's cipher library, and many cloud key management services prefer PKCS#8.
Additionally, both PKCS#1 and PKCS#8 secret keys can be protected with PEM-level locking using a passphrase. The selected cipher (commonly AES-256) secures the key bytes at rest using a PKCS#5-derived key from your passphrase. This passphrase protection means that even if the container is exposed, an attacker cannot use the secret key without the passphrase. A pem passphrase is strongly recommended for any secret key stored on disk. This layer of data security is a critical part of sound key management.
WARNING: A pem passphrase cannot be recovered. If you forget it, you must generate a replacement key pair and rotate dependent systems. Always keep a protected backup of your passphrase in a vault or hardware keystore.
Common RSA Key Applications and RSA Private Key Use Cases
RSA keys power nearly every layer of modern cybersecurity. The following common use cases illustrate how your generated key pair translates into real-world protection infrastructure:
- TLS/SSL Certificates: Secure browser connections rely on RSA keys embedded in digital identity documents. Your server's secret key signs the transport handshake; clients verify using the credential's shareable key, establishing a ciphered channel. This is the foundation of internet data protection.
- JWT Signing: The RS256 method uses RSA to attest JWTs (JSON Web Tokens). Your secret key signs the token; any consumer with the shareable key can verify the attestation without a shared secret. Ideal for distributed API identity verification across services.
- OAuth: Many OAuth 2.0 flows use RSA key pairs to sign assertions and client credentials, enabling verified access without transmitting passwords.
- Code Signing: Software publishers use RSA secret keys to attest release binaries. End users and operating systems verify the digital attestation against the publisher's shareable key before installation — critical for software verification and supply-chain integrity.
- Email Encryption: S/MIME uses RSA to cipher email content. Secure mail tools such as PGP also rely on RSA key pairs to protect messages, combining ciphering with attestation for authenticity. End-to-end protected messaging apps follow the same principle.
- PGP/GPG: The PGP/GPG ecosystem uses RSA keys for ciphering, attesting, and key establishment. GPG's web-of-trust model relies on shareable key distribution so that recipients can verify sender identity.
- VPN: IPsec configurations in enterprise tunnel deployments use RSA for identity verification and secure key exchange, with each peer referencing the public key infrastructure of the other. Secure tunnel setups benefit from hashing algorithms during the handshake phase for integrity checks.
- Messaging: Protocols implementing end-to-end protection use RSA during the initial handshake to exchange symmetric cipher keys securely, before switching to a faster method (typically AES) for the bulk of data decryption and encoding.
SSH login deserves special mention: a key pair generated with ssh-keygen uses RSA (or other methods) so that a server can verify your identity using your shareable key without ever seeing your secret key. This is among the most widespread applications in day-to-day developer workflows.
Generate RSA Keys Locally — OpenSSL, Node.js & Python Implementation Examples
For production use, generate RSA keys locally on a trusted machine using reviewed cipher tooling — not a web interface. Browser generation is excellent for learning and prototyping, but production keys for live services should originate from a secure, air-gapped or hardware-backed environment. The implementation examples below are copy-paste ready and cover the three most common environments.
OpenSSL — Command-Line Key Generation
OpenSSL is the most widely used command-line key tool for server environments. You will need a shell with OpenSSL installed. The following sequence generates a secret key, derives the corresponding shareable key, and then demonstrates how to encrypt data and decrypt a file named input.txt — helping you decrypt file contents using your generated credentials.
# Step 1: Generate a 2048-bit RSA private key (no passphrase)
$ openssl genrsa -out key.pem 2048
# Step 1a: Generate with passphrase protection using AES-256 (recommended for production)
$ openssl genrsa -aes256 -out key.pem 4096
# Step 2: Derive the public key from the secret key file using openssl rsa pubout
$ openssl rsa -in key.pem -pubout -out pubkey.pem
# Step 3: Encrypt input.txt using the shareable key (pubin flag reads a standalone public key)
$ openssl rsautl -encrypt -inkey pubkey.pem -pubin -in input.txt -out input.txt.enc
# Step 4: Decrypt the ciphered file using the inkey flag pointing to the secret key
$ openssl rsautl -decrypt -inkey key.pem -in input.txt.enc -out input.txt
# SSH key pair generation for server login
$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsaIMPORTANT: For any key that will protect real data, always use the -aes256 flag with openssl genrsa to enable passphrase protection on your secret key file. Store your shareable key file freely; never commit your secret key to source control. The pubout and pubin flags instruct the OpenSSL commands to read or write a standalone shareable key file rather than embedded key data. The output file input.txt.enc is the ciphered result that only the holder of the secret key can recover — demonstrating decrypted data retrieval via the pasted private key or key file in practice.
Node.js Encryption — Built-In Crypto Module
Node.js ships with the crypto module, making it straightforward to load your PEM files and perform RSA-OAEP ciphering and recovery programmatically. The following example also shows how to generate a fresh key pair and write both key files to disk — a pattern common in microservice bootstrap scripts.
const crypto = require('crypto');
const fs = require('fs');
// Programmatic key pair generation — writes secret key and shareable key files to disk
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048, // key length in bits
publicKeyEncoding: { type: 'pkcs1', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
});
fs.writeFileSync('mykey.pem', privateKey);
fs.writeFileSync('mypubkey.pem', publicKey);
// Load RSA keys from existing PEM files
const loadedPublicKey = fs.readFileSync('mypubkey.pem', 'utf8');
const loadedPrivateKey = fs.readFileSync('mykey.pem', 'utf8');
// Cipher data using RSA-OAEP with SHA-256
function encryptRSA(data, pubKey) {
return crypto.publicEncrypt({
key: pubKey,
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
oaepHash: 'sha256' // hash selector for the OAEP mask
}, Buffer.from(data));
}
// Recover ciphered data — only the secret key holder can reverse the operation
function decryptRSA(encryptedData, privKey) {
return crypto.privateDecrypt({
key: privKey,
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
oaepHash: 'sha256'
}, encryptedData);
}
const message = 'Protect sensitive data with RSA!';
const encrypted = encryptRSA(message, loadedPublicKey);
const decrypted = decryptRSA(encrypted, loadedPrivateKey);
console.log('Decrypted:', decrypted.toString());
// The built-in encrypt and decrypt helpers handle all padding internallyThe built-in publicEncrypt and privateDecrypt functions implement the RSA PKCS1 OAEP padding method, which is the modern, secure standard. Using SHA-256 as the hash function ensures the ciphered output is resistant to chosen-ciphertext attacks. This approach provides strong data protection for sensitive payloads, and the decrypted data is returned as a plain Buffer.
Python Digital Signatures — cryptography.hazmat Primitives
Python's cryptography library provides low-level hazmat primitives for RSA key generation, attesting, and validity checking. The example below mirrors the Python digital-signature workflow: generate a secret key with public exponent 65537, sign a message using PSS padding with a mask generation function and SHA-256, then confirm the attestation using the extracted shareable key.
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import rsa, padding
# Generate secret key — public exponent 65537 is standard; key_size sets the modulus length
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048
)
public_key = private_key.public_key() # derive shareable key from secret key
# Serialize to PEM — secret key as PKCS#8, shareable key as SubjectPublicKeyInfo
private_pem = private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption()
)
public_pem = public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo
)
# Attest data — PSS padding with mask generation function provides approved digital-signature generation
def sign_data(data, private_key):
return private_key.sign(
data.encode('utf-8'),
padding.PSS(
mgf=padding.MGF1(hashes.SHA256()), # mask generation function
salt_length=padding.PSS.MAX_LENGTH
),
hashes.SHA256() # PSS padding uses SHA-256 as the digest
)
# Confirm attestation — proves authenticity and message integrity
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 Exception:
return False
message = 'Important document — verify me'
signature = sign_data(message, private_key)
is_valid = verify_signature(message, signature, public_key)
print(f'Valid signature: {is_valid}')The PSS (Probabilistic Signature Scheme) with PSS padding and a mask generation function is recommended for new RSA applications. The public_exponent=65537 is the universally accepted standard value — it balances protection and computation cost. This workflow covers key generation, PEM serialization, attesting, and signature verification in a single self-contained script. The compression of key metadata into the PEM container simplifies portability across systems.
IMPORTANT: For production keys, always generate locally using operating system tools or a hardware-backed keystore rather than any online tool. Store secret keys in a dedicated vault, never in source control. Implement key rotation policies and key backup procedures, and restrict access to the minimum required set of processes and users. Following key management best practices — including export controls and import validation — is as important as the key length itself.
Frequently Asked Questions
- Is this real RSA, or a simulation?
- It's real RSA, generated by your browser's native Web Crypto API -- the same audited cryptographic implementation Chrome, Firefox, and Safari use for TLS and other security-critical operations, not a JavaScript reimplementation. The keys are fully standard and interoperable with OpenSSL, SSH, and any other RSA-compatible tool.
- 2048-bit or 4096-bit -- which should I choose?
- 2048-bit is still considered secure for the foreseeable future and is the current default for TLS certificates and most RSA use cases -- it's also noticeably faster to generate and use. 4096-bit offers a larger security margin for long-lived keys or particularly sensitive use cases, at the cost of slower generation and slightly slower operations.
- Why does key generation take a few seconds?
- Finding two large prime numbers that satisfy RSA's mathematical requirements is inherently expensive, especially at 4096 bits -- this is normal and happens with any RSA key generator, not just this one. The browser's native implementation is actually faster than most pure-JavaScript alternatives.
- What format is the output in?
- Standard PEM: the public key as SubjectPublicKeyInfo (SPKI), the private key as PKCS#8 -- both directly compatible with OpenSSL (openssl rsa, openssl x509), most programming language crypto libraries, and any tool expecting standard PEM-encoded RSA keys.
- Are my keys sent anywhere?
- No. Both keys are generated and exported entirely in your browser using the Web Crypto API -- nothing is transmitted, logged, or stored. Reload the page and they're gone, so copy or save them before navigating away.