One-Time Pad Tool with HMAC-SHA256

Generate pads, encrypt, decrypt, detect tampering — all in one page. Nothing leaves your browser.

⚠ Read this before using A one-time pad is only unbreakable if the key is (1) truly random, (2) at least as long as the message, (3) never reused, and (4) kept secret. This tool enforces (1) via crypto.getRandomValues and (2) by refusing short pads. The pad is split: the first N bytes encrypt an N-byte message, and a separate 32-byte segment (taken from after the message bytes) authenticates it with HMAC-SHA256. So you need message length + 32 bytes per message. It cannot enforce (3) or (4) — that's on you.

1. Generate a pad

= max plaintext bytes (length − 32 for HMAC)

2. Encrypt or decrypt

Plaintext (to encrypt) or tagged ciphertext (to decrypt):
0 bytes
Pad (hex or Base64):
0 bytes available
Result:
How the HMAC tag works

Encrypting an N-byte message consumes N + 32 bytes of pad:

After XORing, the tool computes HMAC-SHA256(hmac_key, ciphertext) and appends the 32-byte tag to the ciphertext. The output is ciphertext || tag (N + 32 bytes total), shown as hex or Base64.

On decryption, the recipient pulls the tag off the end, recomputes the HMAC over the ciphertext with the same pad bytes, and compares. If the tag doesn't match, the tool refuses to decrypt and tells you the message was altered or the wrong pad was used. This is critical: an unauthenticated OTP lets an attacker flip specific plaintext bits by flipping ciphertext bits. With the tag, any modification is caught.

Why a separate HMAC key? Reusing the same pad bytes for both XOR and HMAC would violate the one-time property — the pad would be doing two jobs. Taking the HMAC key from later in the pad keeps the two roles independent, and those bytes are never used for anything else.

Comparison is constant-time (via crypto.subtle.verify), so timing side-channels can't leak tag bytes.