Skip to content
shellhacks.dev

RSA Encrypt and Decrypt

Encrypt a short message with an RSA public key and decrypt it with the private key using RSA-OAEP and SHA-256, or generate a 2048-bit key pair to try it.

Free · No sign-up · Your inputs stay in your browser

Input

Encrypt and decrypt with RSA-OAEP

Output

Result

0 characters

RSA encrypts only a few hundred bytes, so real systems encrypt the data with a random AES key and RSA-encrypt that key (hybrid encryption, which is what age, PGP and TLS do). OAEP padding with SHA-256 is the safe choice; the older PKCS#1 v1.5 encryption padding is open to padding-oracle attacks. Compatible with openssl pkeyutl -encrypt -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256.

Runs in this browser. Nothing you paste is sent to a server.

RSA encrypts keys, not data

A 2048-bit RSA key with OAEP and SHA-256 encrypts at most 190 bytes. Real systems generate a random symmetric key, encrypt the data with AES, and encrypt only that key with RSA: hybrid encryption, which TLS, PGP and age all use. RFC 8017 defines OAEP.

Padding matters

The older PKCS#1 v1.5 encryption padding is vulnerable to padding-oracle attacks (Bleichenbacher's), so new code should use OAEP. Signing is a separate operation with its own padding schemes.

Share

Frequently asked questions

How much data can RSA encrypt?
The key size in bytes minus 66 with OAEP and SHA-256: 190 bytes for 2048-bit keys, 446 for 4096-bit.
How do I do the same with OpenSSL?
openssl pkeyutl -encrypt -pubin -inkey public.pem -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256 -in msg.txt -out msg.bin, and -decrypt with the private key.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Go deeper

Suggested reading

Keep planning

Similar tools