b2KIT

RSA Encryption Tool

Generate RSA key pairs and encrypt/decrypt messages using RSA-OAEP with the WebCrypto API.

Tested tool guide Tested browser tools Checked August 16, 2026

What RSA Encryption Tool does, with a checked example

RSA-OAEP encrypts a message with a public key so that only the matching private key can decrypt it. This tool generates a fresh key pair in the browser, then encrypts and decrypts text with the WebCrypto implementation of RSA-OAEP, the standard padding scheme for RSA encryption. The surprise is scale: RSA is not a general message encoder. A 2048-bit key carries at most 190 bytes of plaintext with SHA-256 OAEP, and the same message produces different ciphertext on every run because OAEP adds random padding. Nothing you enter or generate ever leaves the page.

Worked example

A concrete input and expected output from the current implementation.

Input

Hello, world! (encrypt with the public key of a freshly generated 2048-bit pair)

Expected output

A 256-byte ciphertext (344 characters if displayed as base64) that differs on every run; decrypting it with the private key returns exactly 'Hello, world!'.

RSA-OAEP is randomized: the padding layer draws a fresh random seed per encryption, so the ciphertext cannot be predicted or reproduced, yet always decodes back to the same message. The 256-byte length is fixed by the 2048-bit modulus, not the 13-byte message.

How the result is produced

1

Key pair generation

The browser generates two large primes p and q and computes the modulus n = p*q; the public key is (n, e) with e usually 65537, and the private key is the exponent d that inverts e modulo (p-1)(q-1). WebCrypto performs this in one asynchronous call, and the key material lives only in the page's memory - nothing is sent over the network.

2

OAEP padding and message limits

Before encryption, EME-OAEP mixes the message with a random seed using hash-based masks, and the padded result must fit inside the modulus. Plaintext is therefore capped at k - 2*hLen - 2 bytes (190 bytes for a 2048-bit key with SHA-256), while the ciphertext is always exactly k bytes. Decryption reverses the masks and verifies the padding, so the wrong key yields an error rather than garbage.

Good uses

  • Send someone a secret: they give you their public key, you encrypt a password or access token with it, and only their private key can ever open it.
  • Check a generated pair before use: encrypt a test phrase with your own public key and decrypt it back, confirming the pair is consistent before you distribute the public key.
  • Wrap a symmetric key in a hybrid scheme: encrypt a 32-byte AES key with RSA so that a long file encrypted under the AES key is protected by the RSA pair.

Limits and checks

  • Size cap: RSA-OAEP holds at most k - 2*hLen - 2 plaintext bytes (190 for a 2048-bit key with SHA-256). Long text or a file will not encrypt; wrap a symmetric key instead.
  • Randomized output: the same message gives different ciphertext on every run, and length never varies (256 bytes for a 2048-bit key), so you cannot compare two encryptions to check whether the plaintexts match.
  • Wrong key and lost key: decrypting with the wrong private key fails with an error because OAEP padding does not verify, and if the private key is lost the ciphertext is unrecoverable: nothing can decrypt it.

Common questions

Why does the same message encrypt to a different result every time?

RSA-OAEP intentionally mixes a fresh random seed into the padding before each encryption, as specified in RFC 8017, so ciphertext is nondeterministic. This prevents attackers from learning anything by comparing two encryptions of the same text. Every run decrypts to the same message, so the changing output is not a bug.

Can this tool encrypt a long file or message?

No. RSA-OAEP fits only k - 2*hLen - 2 bytes of plaintext per operation, which is 190 bytes for a 2048-bit key with SHA-256. Production systems therefore use hybrid encryption: RSA encrypts a small symmetric key, and that key encrypts the actual data with AES or similar.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools