RSA Encryption Online: How to Encrypt Messages With an RSA Public Key
CodexFuse Team · 2026-10-13T14:25:44.115Z · 6 min read min read
RSA encryption lets anyone lock a message with a public key so only the matching private key can open it. Learn how it works and how to use it.
You need to send a secret to someone you have never met, over a channel anyone can read. That sounds impossible, yet it is exactly what RSA encryption is built for. The recipient publishes a public key, you lock your message with it, and only the recipient's private key can open it.
This guide explains how RSA encryption works, how to encrypt a message with a public key, and where its limits sit. You will also learn how to share keys safely. Pair it with our rsa decryption for the complete toolkit.
What Is RSA Encryption?
RSA encryption locks a message with the recipient's public key so that only the matching private key can open it. Anyone can encrypt with a public key, but only the private key holder can decrypt. This asymmetry is what lets two people who have never met exchange a secret over an open channel.
The two keys are a matched pair. The public key can be shared freely, and the private key must stay on its owner's machine.
The two keys at a glance
- Public key: shared openly, used to encrypt messages for its owner.
- Private key: kept on the owner's machine, used to decrypt those messages.
- Key pair: generated together, and only the matching halves work with each other.
The CodexFuse RSA encryption tool takes a public key and a short message and returns ciphertext that only the matching private key can open.
| Action | Key used | Who can do it |
|---|---|---|
| Encrypt a message | Recipient's public key | Anyone |
| Decrypt a message | Recipient's private key | Only the recipient |
| Share a key openly | Public key | Anyone |
How Do I Encrypt a Message With an RSA Public Key?
Get the recipient's public key and confirm it really belongs to them. Paste the public key and your short message into the encryption tool — it uses RSA-OAEP with SHA-256, so there is no padding setting to choose — and run the encryption. Send only the resulting ciphertext to the recipient, who opens it with their private key on their own machine.
Learn with a test key pair: generate a fresh pair meant only for practice, encrypt a test message with the test public key, and decrypt it with the test private key on your own machine.
Steps with a test key pair
- Get the recipient's public key, or generate a test key pair with the RSA key generator for practice.
- Open the RSA encryption tool and paste the public key, including its header and footer lines.
- Type a short test message. The tool always uses RSA-OAEP with SHA-256, so the recipient must decrypt with the same padding.
- Run the encryption and copy the ciphertext exactly.
- Send only the ciphertext to the recipient, who decrypts it as described in our guide on RSA decryption with a private key.
Rule of thumb: encrypt with a public key you have verified. A message locked with the wrong key opens for the wrong person.
Keep the message short. RSA handles one small block per operation, so a long message needs a different approach, covered in the limits section below.
What Are the Limits of RSA Encryption?
RSA can only encrypt a short block in one operation, so it cannot handle long messages directly. It is also slower than symmetric encryption, which is why real systems use RSA to protect a symmetric key and let that key protect the message. Padding must match on both sides, or decryption fails.
In practice, the sender generates a random symmetric key, encrypts the message with it, and encrypts that small key with the recipient's public key. The recipient reverses the process to open the message.
Limits to plan around
- Message size: one RSA operation carries only a short block, set by the key size and padding.
- Speed: RSA math is slower than symmetric encryption, so bulk data uses a symmetric cipher.
- Padding: the sender and receiver must use the same padding, or decryption fails.
- Key trust: RSA cannot tell you whether a public key is genuine, so verify it first.
Consider a fictional example. A team wants to share a login credential with a contractor. Instead of pasting it into chat, they encrypt a short note with the contractor's verified public key and send the ciphertext. The contractor decrypts it with the private key on their own machine. The channel was public, but the secret stayed private.
CodexFuse helps businesses run managed hosting, encryption, and access controls with secure defaults handled for you, fully managed on pay-as-you-go credits.
Get Started with CodexFuseHow Do I Share a Public Key Safely?
Share a public key through a channel the recipient can verify, such as a signed page, a verified profile, or a direct handoff, and include a fingerprint they can check. Public keys are not secret, but a substituted key is dangerous: a message encrypted with an attacker's key can only be opened by the attacker.
A fingerprint is a short digest of the key that is easy to compare over a second channel. If you send a key by email, confirm its fingerprint by phone or in person.
Key-sharing checklist
- Publish the public key where the recipient expects to find it.
- Share the fingerprint through a separate, trusted channel.
- Ask the recipient to confirm the fingerprint before encrypting anything sensitive.
- Replace the key pair if the private key is ever exposed or its ownership is in doubt.
The same care applies to the secrets behind your keys. Our password generator guide covers building strong secrets, and our entropy calculator guide explains how key size and randomness set the strength of an RSA key pair.
How Long a Message Can RSA Encryption Handle?
RSA encrypts one small block per operation, and the block size is set by the key size minus the padding overhead. This tool uses RSA-OAEP with SHA-256, whose overhead is 2 × 32 + 2 = 66 bytes (twice the 32-byte SHA-256 digest, plus 2). The maximum message length is therefore (key size in bits ÷ 8) − 66 bytes:
| Key size | Max message (RSA-OAEP, SHA-256) |
|---|---|
| 1024-bit | 62 bytes |
| 2048-bit | 190 bytes |
| 3072-bit | 318 bytes |
| 4096-bit | 446 bytes |
Anything longer needs hybrid encryption: generate a random AES key, encrypt the message with it, then encrypt only that small key with the recipient’s RSA public key. That is how real systems move large files and long messages with RSA — the public-key operation protects the key, and the symmetric cipher protects the data.
RSA encryption turns an open channel into a private one, as long as the basics hold: verify the public key, keep messages short or use a hybrid scheme, match the padding, and keep private keys on their owners' machines. Also worth reading: RSA Key Generator Online — Create RSA Public & Private Key Pairs Free.
Frequently Asked Questions
Can anyone decrypt a message encrypted with my public key?
No. Only the matching private key can decrypt it. Anyone can encrypt with your public key, but the ciphertext stays unreadable to everyone except the holder of that private key.
What padding does the RSA encryption tool use?
RSA-OAEP with SHA-256, always — the tool has no padding setting. That is the modern standard, and the recipient must decrypt with the same padding or the operation fails. Ciphertext made with the older PKCS#1 v1.5 padding cannot be opened with this tool.
Why is my message too long for RSA?
RSA encrypts only a short block per operation, so a long message exceeds that limit. Use a hybrid scheme: encrypt the message with a symmetric key, then encrypt that small key with RSA.
Should I encrypt with a private key instead?
No. Encrypting with a private key does not keep a message secret, since anyone with the public key could reverse it. Private keys are for decrypting and signing, while public keys are for encrypting.
How do I know a public key is genuine?
Verify it through a trusted channel. Compare the key fingerprint with the owner over a second channel, or use a signed directory or verified profile. Never encrypt a sensitive message with a key you have not verified.
What public key format does the RSA encryption tool need?
A PEM-encoded SPKI public key — the text block that starts with -----BEGIN PUBLIC KEY----- and ends with -----END PUBLIC KEY-----. In decrypt mode the tool instead expects a PKCS#8 private key (-----BEGIN PRIVATE KEY-----). Keys in other formats, such as an SSH public key or a certificate, must be converted to PEM first.
Can I change the padding the tool uses?
No. The tool always uses RSA-OAEP with SHA-256 and offers no padding setting. If the other side encrypted with PKCS#1 v1.5 or a different hash, run a matching tool on both ends instead — the padding must be identical or decryption fails.















