Public key message encrypter

Encrypt a short message to someone's RSA public key, and decrypt it with the matching private key, all in your browser.

Everything runs in your browser using RSA-OAEP. Your message and keys are never uploaded. RSA can only encrypt a short message directly (about 190 bytes with a 2048-bit key); longer text is rejected, which is why real systems use hybrid encryption.

How do I encrypt a message with a public key?

Paste the recipient's RSA public key (PEM) and your message, and this tool encrypts it with RSA-OAEP so that only the matching private key can read it. The result is base64 that you can send anywhere. To read a message, switch to Decrypt, paste the private key and the base64. Everything runs in your browser and nothing is uploaded.

Encrypt with the public key, decrypt with the private key

Asymmetric encryption solves a problem that shared-password encryption cannot: how do two people agree on a secret without a safe way to exchange one first? With a key pair, the answer is that they do not have to. The recipient keeps a private key to themselves and publishes the matching public key. Anyone can take that public key and encrypt a message with it, but the result can only be opened by the private key. So you can encrypt something to a person you have never spoken to privately, and only they can read it.

This tool does exactly that with RSA-OAEP. In Encrypt mode, paste the recipient's public key and your message, and it returns a base64 block you can send by email or chat. In Decrypt mode, the recipient pastes their private key and that base64 to recover the text. Every step runs in your browser through the WebCrypto API, so no message and no key is ever uploaded.

The RSA size limit, and why it exists

RSA cannot encrypt an arbitrary amount of data directly. The message has to fit inside the key, minus the space that the OAEP padding needs. With SHA-256 padding, the usable room is the key size in bytes minus 66. That gives small, fixed limits.

RSA 2048 (256-byte key)
256 minus 66 = 190 bytes of message, roughly 190 plain ASCII characters.
RSA 4096 (512-byte key)
512 minus 66 = 446 bytes of message.

If you paste more than that, this tool stops you with a clear message rather than failing in a confusing way. It is not a bug: RSA was never meant to encrypt bulk data.

How real systems handle longer messages

Because of that limit, no real system encrypts a whole email or file with RSA directly. Instead they use hybrid encryption. A fresh random symmetric key (for a fast cipher like AES) is generated, the actual message is encrypted with AES, and then only that small AES key is wrapped with the recipient's RSA public key. The recipient uses their private key to unwrap the AES key, then decrypts the message with it. You get the convenience of public-key exchange and the speed and unlimited length of symmetric encryption at the same time. TLS, encrypted email and messaging apps all work broadly this way.

Hybrid encryption, in one line
Encrypt the message with a random AES key, then RSA-encrypt only that AES key.

For shared-password symmetric encryption on this site, see the AES text encrypter, which handles text of any length with a single passphrase.

Pairing with the key pair generator

This tool is the companion to the key pair generator. Generate an RSA 2048 or RSA 4096 pair there, keep the private key somewhere safe, and hand out the public key. Anyone with your public key can send you a short encrypted note that only you can open, with no password to agree on beforehand. Note that EC keys will not work here, because RSA-OAEP needs an RSA key; generate an RSA pair for this use.

The strength of the whole scheme rests on the private key staying private, so never paste a private key anywhere you do not trust and never share it. This is general guidance, not security advice for a specific system.

How we work it out

The PEM key is stripped of its header and footer and base64-decoded to DER, then imported with crypto.subtle.importKey (SPKI for the public key, PKCS8 for the private key) under RSA-OAEP with SHA-256. Encryption uses crypto.subtle.encrypt and the output is base64; decryption reverses it. A 2048-bit key can carry roughly 190 bytes of message, so longer text is rejected with a clear explanation.

Frequently asked questions

Is my message or key sent anywhere?

No. All importing, encryption and decryption happens in your browser using the built-in WebCrypto API. Your message, the public key and the private key never leave your device, so the tool is safe to use with private information.

Where do I get the keys?

Use the key pair generator on this site, or any tool that produces standard PEM keys. The person receiving the message generates a pair, keeps the private key and gives you the public key. You encrypt with their public key; only they can decrypt, because only they hold the private key.

Why does it refuse my long message?

RSA can only encrypt a small amount of data directly, a little less than the key size. A 2048-bit key handles about 190 bytes with SHA-256, and 4096-bit about 446 bytes. Longer text is rejected on purpose rather than failing cryptically. Real systems solve this with hybrid encryption, described below.

How is this different from the AES text encrypter?

The AES tool uses one shared password to both lock and unlock the text, so both people need the same secret. This tool uses a key pair: you encrypt with a public key that can be shared openly, and only the holder of the private key can decrypt. That removes the problem of safely sharing a password.

Can I use an EC key here?

No. This tool uses RSA-OAEP, which needs an RSA key. Elliptic-curve keys are used for signing or key agreement rather than directly encrypting a message, so generate an RSA pair in the key pair generator if you want to use this tool.

Related tools