RSA Encryption and Decryption Online

RSA(Rivest-Shamir-Adleman) is an asymmetric encryption technique that uses two different keys as public and private keys to perform the encryption and decryption. With RSA, you can encrypt sensitive information with a public key and a matching private key is used to decrypt the encrypted message. Asymmetric encryption is mostly used when there are 2 different endpoints are involved such as VPN client and server, SSH, etc.

Below is an online tool to perform RSA encryption and decryption as an RSA calculator.

Generate RSA Key Pair (Optional)

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



We do not store or log any key you enter. This tool is intended for personal and educational use. Do not use online tools to protect real production secrets.

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 encryption and decryption.

Ciphertext Too Large for RSA Key

RSA is not designed to encrypt large data or files directly. If the plaintext size exceeds the RSA key limit, encryption or decryption will fail.

Fix: Use hybrid encryption — encrypt the data using AES, and 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.

Fix: Ensure private keys are PKCS#8 encoded and public keys are X.509 encoded.

You can validate your setup using our Crypto Safety Validator.

Secure Usage Guidelines for RSA

  • Use RSA only for key exchange or small secrets
  • Prefer RSA-OAEP over PKCS#1 v1.5
  • Use a minimum key size of 2048 bits
  • Never encrypt large files directly with RSA

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

When NOT to Use RSA Encryption

For Java implementation of RSA, you can follow this article .

By default, the private key is generated in PKCS#8 format and the public key is generated in X.509 format .

Key Features of RSA

  • Asymmetric Key Algorithm: Uses a public and private key pair
  • Security Basis: Depends on the difficulty of factoring large primes
  • Variable Key Lengths: 1024, 2048, and 4096 bits
  • Use Cases: Secure communication, digital signatures, key exchange

Key Concepts

  • Public Key: Composed of modulus n and exponent e
  • Private Key: Uses exponent d derived from Euler’s totient function

Security Considerations

  • Key Size: Larger keys provide stronger security
  • Padding: Correct padding prevents cryptographic attacks
  • Key Management: Private keys must be securely stored

RSA Padding Schemes

OAEP is recommended for modern applications as it protects against chosen-ciphertext attacks.

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

Frequently Asked Questions

Why does RSA decryption fail?

Most failures are caused by padding mismatch, incorrect key usage, or attempting to decrypt data larger than the key size allows.

Is RSA safe for file encryption?

No. RSA should only be used for encrypting small secrets or keys. For files, use PGP or AES-based encryption or try Devglan's file encryption tool.

Which RSA padding scheme should I use?

RSA-OAEP is recommended for modern secure applications.

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