RSA Key Generator - Generate 2048, 3072 & 4096-bit Keypairs
Generate public and private RSA keypairs (2048, 3072, and 4096-bit) in PEM (PKCS#1 / PKCS#8) and OpenSSH formats online.
RSA Key Generator
Generate public and private RSA keypairs (2048, 3072, and 4096-bit) in PEM (PKCS#1 / PKCS#8) and...
Useful SSH & OpenSSL Commands
chmod 600 ~/.ssh/id_rsa chmod 644 ~/.ssh/id_rsa.pub
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa
openssl rsa -in id_rsa -pubout -out public.pem
ssh -T git@github.com
About RSA Key Generator
What is an RSA Key Generator & How Does It Work?
The ToolSpark RSA Key Generator is an online cryptographic tool designed for developers, systems administrators, and DevOps professionals who require standard PKCS#1 and PKCS#8 asymmetric RSA key pairs. Executing directly inside your web browser via the standard W3C Web Cryptography API (`crypto.subtle.generateKey`), this utility generates mathematically rigorous prime factors to synthesize private and public keys in standard PEM (Privacy-Enhanced Mail) formatting without transmitting sensitive private data over the internet.
The Mathematics Behind RSA Cryptography
Named after its inventors Ron Rivest, Adi Shamir, and Leonard Adleman, the RSA algorithm derives its cryptographic strength from the computational hardness of the integer factorization problem:
- Two massive, distinct random prime numbers $p$ and $q$ are chosen via cryptographically secure pseudo-random number generators (CSPRNG).
- The modulus $n = p imes q$ is calculated. The length of $n$ in bits determines the key length (e.g., 2048, 3072, or 4096 bits).
- Euler's totient function $\phi(n) = (p-1)(q-1)$ is computed.
- A public exponent $e$ (commonly 65537, or $2^{16} + 1$) is selected such that $\gcd(e, \phi(n)) = 1$.
- The private exponent $d$ is computed as the modular multiplicative inverse: $d \equiv e^{-1} \pmod{\phi(n)}$.
The public key is $(n, e)$, and the private key is $(n, d)$. While multiplying $p$ and $q$ takes microseconds, factorizing $n$ back into $p$ and $q$ without knowledge of $d$ would take millions of years with modern supercomputers.
---
Realistic Worked Examples
Example 1: Creating an API Signing Key Pair (RSA 2048-bit)
- Parameters: 2048-bit key depth, PKCS#8 PEM format.
- Output:
- Private Key: `-----BEGIN PRIVATE KEY-----` (Base64 ASN.1 sequence containing $n, e, d, p, q, d_p, d_q, q_{inv}$)
- Public Key: `-----BEGIN PUBLIC KEY-----` (Base64 SubjectPublicKeyInfo containing $n$ and $e$)
- Use Case: Used by an authentication server to issue and sign asymmetric JWT tokens (`RS256`).
Example 2: Enterprise Root Certificate Key (RSA 4096-bit)
- Parameters: 4096-bit key depth.
- Use Case: Used as the private key foundation for generating self-signed TLS certificates and OpenSSL certificate signing requests (CSRs).
---
Step-by-Step Guide: How to Generate RSA Keys
- Select Key Size: Choose between 2048-bit (standard commercial speed), 3072-bit (NIST recommended through 2030), or 4096-bit (maximum enterprise resilience).
- Choose Output Format: Select standard PKCS#8 (universal modern standard) or legacy PKCS#1 format.
- Click "Generate Key Pair": Your browser generates high-entropy prime numbers and builds the ASN.1 structures.
- Copy or Download Keys: Download the public key (`public.pem`) and private key (`private.pem`) for use in OpenSSL, Node.js, Python, or Go applications.
---
Who Uses This Tool & Practical Scenarios
- Backend Developers: Implementing asymmetric encryption for payment tokenization, payload verification, and webhook authenticity.
- DevOps Engineers: Generating key pairs for service-to-service mutual TLS (mTLS), Kubernetes secrets, and OpenSSL configurations.
- Cloud Architects: Configuring AWS CloudFront signed URLs and private API gateway authentication policies.
- Security Students: Studying the mathematical structure and ASN.1 formatting of modern public-key cryptography.
---
Security Best Practices
- 2048-bit Minimum: Never use RSA keys smaller than 2048 bits for production environments. NIST recommends 3072 or 4096-bit keys for long-term security.
- Client-Side Generation Only: Never generate production root production keys on public shared computers. ToolSpark processes everything client-side for rapid development and testing.
Complement your setup with our SSH Key Generator, create authentication tokens with JWT Generator & Decoder, or inspect certificates with SSL Certificate Checker.
---
Asymmetric Key Cryptography, Prime Number Generation & Modulus Sizes
The RSA cryptosystem (Rivest–Shamir–Adleman) forms the bedrock of secure internet communications, TLS handshakes, and enterprise encryption:
- Choosing Modulus Bit Length (2048 vs. 4096 bits):
- 2048-bit RSA: Currently provides acceptable security (equivalent to approximately 112 bits of symmetric security) according to NIST guidelines, suitable for general application testing and short-term keys.
- 4096-bit RSA: Recommended for long-term root Certificate Authorities (CAs), master PGP identities, and enterprise archival encryption, offering robust resistance against escalating factoring capabilities.
- The Importance of Large Prime Generation: RSA security rests upon the computational difficulty of factoring the product ($n = p imes q$) of two massive, randomly generated prime numbers. Generating cryptographically secure primes requires continuous entropy gathering from system hardware events (`crypto.getRandomValues`) to prevent prime predictability.
- Public Exponent Standard ($e = 65537$): The fourth Fermat number ($F_4 = 2^{16} + 1 = 65537$) is universally utilized as the standard public exponent. Its binary structure contains only two set bits (`10000000000000001`), providing lightning-fast modular exponentiation while defending against low-exponent factoring attacks.
Regulatory & Enterprise Standards
- PKCS #1 (RFC 8017): RSA Cryptography Specifications Version 2.2.
- Format Exports: PEM-encoded PKCS#1 (`BEGIN RSA PRIVATE KEY`) and PKCS#8 (`BEGIN PRIVATE KEY`) formats for universal server compatibility.
- Related Key Tools: Compare with our modern SSH Key Generator, PGP Key Generator, and AES Encrypt / Decrypt.