CommandDialog

RSA Key Pair Generator

Generate RSA key pairs (PEM format) with key length up to 4096 bit. All operations are in your browser, your private key never leaves your device.

Related Tools

What Is an RSA Key Pair Generator?

In today’s digital landscape, data security and privacy protection have become top priorities for developers and organizations alike. Whether you are configuring SSH access, authenticating with GitHub, or building encrypted communication software, a secure and reliable RSA key pair is a fundamental requirement.

Our RSA Key Pair Generator is a tool that uses the RSA algorithm to generate a pair of mathematically related keys—a Public Key and a Private Key. It is designed to provide a fast, free, and highly secure online RSA generation experience, supporting industrial-grade key sizes of 1024, 2048, and up to 4096 bits.

  • Public Key: Can be shared with anyone and is used to encrypt data or verify digital signatures.
  • Private Key: Must be kept strictly confidential and is used to decrypt data encrypted with the public key or to create digital signatures.

This mechanism is known as Asymmetric Encryption, and it forms the foundation of modern Internet security protocols such as HTTPS/TLS, SSL, and SSH.

How the RSA Algorithm Works

RSA is based on a fundamental principle of number theory: multiplying two very large prime numbers is computationally easy, but factoring their product back into the original primes (the large integer factorization problem) is extremely difficult with current computing power. The core steps are as follows:

1. Choose Base Primes

Randomly select two distinct, very large prime numbers, denoted as pp and qq.

2. Compute the Modulus and Euler’s Totient

  • Compute the modulus nn: The binary length of nn determines the key size (e.g., 2048 bits). The value of nn is public and is calculated as:

    n=p×qn = p \times q
  • Compute ϕ(n)\phi(n): According to Euler’s totient function, when nn is the product of two primes:

    ϕ(n)=(p1)(q1)\phi(n) = (p - 1)(q - 1)

3. Select the Encryption Exponent ee

Choose an integer ee such that 1<e<ϕ(n)1 < e < \phi(n) and ee is coprime with ϕ(n)\phi(n). In practice, to optimize encryption performance, ee is commonly set to the fixed value 6553765537.

4. Compute the Decryption Exponent dd

Calculate dd as the modular multiplicative inverse of ee, satisfying the following congruence:

ed1(modϕ(n))e \cdot d \equiv 1 \pmod{\phi(n)}

This means that (ed1)(e \cdot d - 1) is divisible by ϕ(n)\phi(n). The value dd is the core component of the private key—only someone who possesses dd can decrypt data encrypted with ee. Therefore, dd must be kept strictly confidential.

5. Form the Key Pair

At this point, all essential parameters are available:

  • Public Key: (n,e)(n, e)
  • Private Key: (n,d)(n, d)

6. Encryption and Decryption Formulas

Once the key pair is generated, secure data transmission follows these rules:

  • Encryption: Convert plaintext MM into ciphertext CC:

    C=Me(modn)C = M^e \pmod n
  • Decryption: Recover plaintext MM from ciphertext CC:

    M=Cd(modn)M = C^d \pmod n

Why Use RSA Encryption?

  1. High Security: With a sufficiently large key size (2048 bits or higher is recommended), RSA is considered infeasible to break within any practical timeframe, even for modern supercomputers.
  2. No Shared Secret Required: Unlike symmetric encryption, RSA does not require parties to exchange a secret key in advance, significantly reducing the risk of key leakage.
  3. Authentication and Integrity: The private key holder can prove their identity through digital signatures, which recipients can verify using the public key to ensure the data has not been tampered with.

Why Choose Our Online RSA Generator?

When selecting an online tool, security is the primary concern. Our solution offers several clear advantages:

Security and Privacy First

Your private key never leaves your device. Many online tools generate keys on a server, meaning the server operator could potentially access your private key. In contrast, all cryptographic operations in our tool are performed locally in your browser and are never uploaded to any server, effectively eliminating the risk of private key leakage.

Multiple Key Length Options

  • 1024 bit: Suitable for legacy systems with low security requirements (not recommended for sensitive data).
  • 2048 bit: The current industry standard, balancing strong security with good performance.
  • 4096 bit: Extremely strong encryption, ideal for long-term storage or environments with strict security requirements.

Standard PEM Output

Generated keys comply with PKCS#1 or PKCS#8 standards and are fully compatible with OpenSSH, OpenSSL, Java, Python, Go, and other development environments. They can be used directly as .pem or .key files.

Ready to Use, One-Click Refresh

A key pair is generated automatically as soon as the page loads. If you want a new one, simply click the “Refresh” button to regenerate instantly—no configuration required.

How to Generate Keys with This Tool

Generating a key pair takes just three simple steps:

  1. Select the key length: Choose the desired size from the dropdown menu (default is 2048 bits).
  2. View the results: The page automatically computes and displays the generated private key and public key. You can also click “Refresh” to generate a new pair.
  3. Copy or download: Use the “Copy” icon or the “Download” button to save the keys to your local machine.

Security Tip: Always keep your private key secure. Never share it with anyone or upload it to public code repositories such as GitHub.

Best Practice: Hybrid Encryption

In real-world applications, RSA involves expensive large-integer exponentiation and is therefore not typically used to encrypt large amounts of data directly. Instead, industry best practice follows a hybrid encryption approach:

  1. Encrypt data symmetrically: Generate a random symmetric key and use a fast symmetric algorithm (such as AES) to encrypt large volumes of plaintext data.
  2. Encrypt the symmetric key: Use the recipient’s RSA public key to encrypt the symmetric key.
  3. Send the payload: Transmit both the encrypted data and the RSA-encrypted symmetric key together.
  4. Decrypt on receipt: The recipient first decrypts the symmetric key using their RSA private key, then uses that key to decrypt the data.

This approach combines the strong security of RSA with the high efficiency of AES.

Frequently Asked Questions

What is the difference between 2048-bit and 4096-bit keys?

A 4096-bit key is more secure than a 2048-bit key, but encryption and decryption operations are slower. At present, 2048-bit keys are considered sufficiently secure for most use cases unless you have very strict compliance or security requirements.

Can a 2048-bit key be cracked today?

With current classical computing power, a 2048-bit RSA key is considered extremely secure. Breaking it would require an astronomically large amount of computational time.

Why is generating a private key online considered safe here?

Online generation is generally discouraged, but our tool uses the Web Crypto API to perform all operations locally in your browser. No data is sent back to the server, providing security equivalent to running commands in a local terminal.

Can I use the generated keys for SSH login?

Yes. Simply add the public key to the server’s ~/.ssh/authorized_keys file and keep the private key stored securely on your local machine.

What does the generated PEM format mean?

PEM (Privacy Enhanced Mail) is a text-based format that encodes binary key data using Base64, making it easy to view, copy, and manage with standard text editors.

What if I lose my private key?

A lost private key cannot be recovered. Due to the one-way nature of RSA, it is impossible to derive the private key from the public key. You must generate a new key pair and replace the associated public key.

Why is my private key much longer than the public key?

The private key contains the modulus n, the public exponent e, the private exponent d, and additional parameters such as p and q used to accelerate computations. The public key typically includes only n and e, so it is much smaller.

Can I generate keys directly from the command line?

Yes. You can run “openssl genrsa -out private.pem 2048” locally. This tool offers equivalent security with greater convenience.