1. Home
  2. Crypto Tools
  3. RSA Encryption and Decryption

RSA Encryption and Decryption Online Tool

This tool is for RSA encryption, decryption and to generate RSA key pairs online. Both public and private keys can be generated for free.

RSA (Rivest-Shamir-Adleman) is an asymmetric encryption algorithm that uses two mathematically linked keys — a public key to encrypt and a private key to decrypt. Because the keys are different, RSA is widely used wherever two separate endpoints need to communicate securely: VPN clients and servers, SSH connections, TLS handshakes, and digital signatures.

Asymmetric Key Pair
Public key encrypts; private key decrypts — keys are never the same
Multiple Padding Schemes
OAEP (recommended), PKCS#1 v1.5, and RSA default
Flexible Key Sizes
512-bit to 4096-bit — generate a key pair directly in the tool

Generate RSA Key Pair

You can generate the required RSA public/Private keys here for encryption and decryption.

Public Key(X.509 Format)


Private Key(PKCS8 Format)


RSA Encryption and Decryption

Below is the tool to perform RSA encryption and decryption. By default, the public/private keys are prepopulated with the keys generated above. You can also supply your own public/private key pairs.

RSA Encryption


RSA Decryption



Common RSA Encryption & Decryption Errors (and Fixes)

RSA Decryption Error: Bad Padding This error occurs when the padding scheme used during encryption does not match the padding used during decryption — for example, encrypting with RSA-OAEP and attempting to decrypt with PKCS#1 v1.5. See RSA Padding Schemes below for details.

Fix: Always use the same padding scheme for both encryption and decryption.

Ciphertext Too Large for RSA Key RSA is not designed to encrypt large data or files directly. If the plaintext exceeds the RSA key size limit (e.g. 2048 bits = 256 bytes minus padding overhead), encryption will fail.

Fix: Use hybrid encryption — encrypt the data with AES, then encrypt the AES key using RSA.

Invalid or Unsupported RSA Key Format RSA operations may fail if the private key is not in PKCS#8 format or the public key is not in X.509 format. By default, this tool generates private keys in PKCS#8 and public keys in X.509 format.

Fix: Ensure private keys are PKCS#8 encoded and public keys are X.509 encoded. Validate your setup with our Crypto Safety Validator.

Key Features, Concepts & Security Considerations

Asymmetric Key Algorithm Uses a mathematically linked public and private key pair. What one key encrypts, only the other can decrypt.
Security Basis RSA security depends on the computational difficulty of factoring the product of two large prime numbers.
Variable Key Lengths Supports 1024, 2048, 3072, and 4096-bit keys. A minimum of 2048 bits is recommended for production use.
Use Cases Secure communication, digital signatures, TLS/SSL handshakes, and symmetric key exchange.
Public Key Structure Composed of modulus n and public exponent e. Safe to share openly.
Private Key Structure Uses private exponent d derived from Euler’s totient function. Must be kept secret and stored securely.

Secure Usage Guidelines for RSA

  • Use RSA only for key exchange or encrypting small secrets — not bulk data
  • Always prefer RSA-OAEP over PKCS#1 v1.5 for new implementations
  • Use a minimum key size of 2048 bits; prefer 4096-bit for long-lived keys
  • Never encrypt large files directly with RSA — use AES with RSA-wrapped key exchange instead
  • Private keys must be securely stored — never hardcode them in source code

Padding selection matters: For secure RSA encryption, use RSA/ECB/OAEPWithSHA-256AndMGF1Padding. PKCS#1 v1.5 and SHA-1 based paddings are provided for legacy compatibility only and may cause decryption errors if mismatched.

When NOT to Use RSA Encryption

  • Large files: Use AES encryption instead — RSA has a strict per-operation size limit
  • Password storage: Use Argon2 or bcrypt — passwords must be hashed, not encrypted
  • Streaming or real-time data: Use ChaCha20 or AES-GCM for high-throughput scenarios

For a Java implementation of RSA encryption and decryption, follow this article.

RSA Padding Schemes

  • PKCS#1 v1.5 — Legacy padding. Vulnerable to certain padding oracle attacks. Explanation
  • OAEP (RSA/ECB/OAEPWithSHA-256AndMGF1Padding) — Recommended for all modern applications. Protects against chosen-ciphertext attacks. Explanation

RSA Encryption Through OpenSSL

Generate Private Key

$ openssl genrsa -out private.pem 2048

Export Public Key

$ openssl rsa -in private.pem -pubout -out public.pem

Encrypt Data

$ openssl rsautl -encrypt -inkey public.pem -pubin -in data.txt -out data.txt.enc

Decrypt Data

$ openssl rsautl -decrypt -inkey private.pem -in data.txt.enc -out data.txt

Applications of RSA

  • SSL/TLS secure communication
  • Digital signatures
  • Secure symmetric key exchange

PGP vs RSA File Encryption

RSA is suitable for encrypting small secrets but not large files. PGP encryption combines RSA with symmetric encryption, making it far more practical for file encryption.

Feature PGP File Encryption RSA Encryption
Large file support Yes No
Multiple recipients Yes No
Hybrid encryption Yes No
Recommended for file sharing Yes Limited

Related Encryption Tools

Frequently Asked Questions

Most failures are caused by a padding scheme mismatch, using the wrong key (public instead of private or vice versa), or attempting to decrypt data larger than the RSA key size allows.
No. RSA should only be used for encrypting small secrets or symmetric keys. For files, use PGP or AES-based encryption, or try Devglan’s file encryption tool.
Use RSA/ECB/OAEPWithSHA-256AndMGF1Padding for all modern applications. PKCS#1 v1.5 is only provided for legacy compatibility and is vulnerable to padding oracle attacks.
A minimum of 2048 bits is recommended. 4096-bit provides a meaningful increase in security for long-lived keys, though it comes with a notable increase in CPU usage. 1024-bit and below are considered broken.
RSA is asymmetric (two different keys) and slow — designed for small data like key exchange. AES is symmetric (same key) and fast — designed for encrypting bulk data. In practice, RSA and AES are often combined: RSA encrypts the AES key, AES encrypts the data.

Support This Free Tool!

I build these tools to give you fast, secure, privacy-friendly utilities—free and signup-free.

Buying me a coffee helps keep the project running and supports new features.

cards
Powered by paypal

Thank you for helping this tool thrive!

References