AES Encryption / Decryption
Encrypt and decrypt text with AES-GCM.Runs in this tab.⌘ ↵ runs it
Next step
Turn a click-through into an interactive demo
AtriumKit records your web app once in Chrome and turns every click into a step of a demo you can embed or share. There’s a free plan.
Try AtriumKit freeAbout AES Encryption / Decryption
Exact parameters
Everything runs through the browser’s Web Crypto API (crypto.subtle) with these settings:
| Step | What the tool uses |
|---|---|
| Key derivation | PBKDF2 with HMAC-SHA-256, 100,000 iterations, 16-byte random salt, 32-byte key |
| Cipher | AES-256-GCM, 12-byte random IV, 128-bit authentication tag, no additional authenticated data |
| Text encoding | UTF-8 for both the plaintext and the password, with no Unicode normalization |
| Output | Standard Base64 with = padding |
What the output contains
The Base64 string decodes to four fields, packed in a row:
| salt | IV | ciphertext | tag |
16 12 n bytes 16
bytes 0–15 salt
bytes 16–27 IV
bytes 28… ciphertext, followed by the 16-byte GCM tag
The ciphertext is the same length as the UTF-8 plaintext, so the output is 44 + n bytes before Base64. hello (5 bytes) comes out as 49 bytes, or 68 Base64 characters. 1,000 bytes of text comes out as 1,392 characters.
The format has no header or version byte, so nothing in it identifies the algorithm. To decrypt elsewhere, you need the parameters above. Encrypting the same text with the same password twice gives different output, because the salt and IV are new each time, and both versions decrypt. A new salt also means a new key for every message. NIST SP 800-38D caps random IVs at 2^32 messages per key, and that limit never comes into play here.
Decrypting outside the browser
Python, with pip install cryptography:
import base64, hashlib
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
data = base64.b64decode(blob)
salt, iv, ciphertext = data[:16], data[16:28], data[28:] # ciphertext ends with the tag
key = hashlib.pbkdf2_hmac('sha256', password.encode(), salt, 100_000, dklen=32)
print(AESGCM(key).decrypt(iv, ciphertext, None).decode())
Node.js:
const crypto = require('node:crypto');
const buf = Buffer.from(blob, 'base64');
const key = crypto.pbkdf2Sync(password, buf.subarray(0, 16), 100000, 32, 'sha256');
const decipher = crypto.createDecipheriv('aes-256-gcm', key, buf.subarray(16, 28));
decipher.setAuthTag(buf.subarray(-16));
console.log(Buffer.concat([decipher.update(buf.subarray(28, -16)), decipher.final()]).toString('utf8'));
Web Crypto and Python’s AESGCM keep the tag attached to the end of the ciphertext. Node handles it separately, through setAuthTag() and getAuthTag(). To produce a string this tool can decrypt, run the same steps in reverse:
const salt = crypto.randomBytes(16), iv = crypto.randomBytes(12);
const cipher = crypto.createCipheriv('aes-256-gcm', crypto.pbkdf2Sync(password, salt, 100000, 32, 'sha256'), iv);
const blob = Buffer.concat([salt, iv, cipher.update(text, 'utf8'), cipher.final(), cipher.getAuthTag()]).toString('base64');
The OpenSSL command line can’t do either direction: openssl enc doesn’t support GCM or any other authenticated mode.
When decryption fails
The error is always “Decryption failed. Check your password and ciphertext.” GCM checks the tag before it returns anything. A wrong password, a single changed or missing character, and a string from another tool all fail the same way, with no partial output.
| What you pasted | Why it fails |
|---|---|
A string starting with U2FsdGVkX1 |
That’s Base64 for Salted__, the OpenSSL enc and CryptoJS AES.encrypt(text, passphrase) format, usually AES-CBC with a different key derivation |
A string containing - or _ |
That’s Base64url. Replace - with + and _ with / |
| Hex output | The tool reads its input as Base64, so hex decodes to the wrong bytes |
| AES-CBC, CTR or ECB ciphertext | There’s no mode setting. The tool only does GCM |
| Data encrypted with a raw key | The key is always derived from a password, and there’s no field for a raw key |
Line breaks or spaces inside the Base64, and missing = padding, are fine. The password has to produce the same UTF-8 bytes on both ends. An é typed as one character and an é pasted as e plus a combining accent look identical, but they derive different keys.
How much the password matters
With 100,000 iterations, every password guess costs 100,000 HMAC-SHA-256 computations. OWASP’s Password Storage Cheat Sheet recommends 600,000 for PBKDF2-HMAC-SHA256, so this setting is on the low side. Anyone with the ciphertext can guess offline, as fast as their hardware allows, so a short or reused password is the weak point, not AES. Use a passphrase of several random words from the passphrase generator.
The tool only encrypts text. To protect a file, Base64-encode it first, and the decrypted output will be that Base64 text. To share messages without sharing a password, use public-key encryption: the PGP key generator or the RSA key generator creates the key pair.
Questions
What encryption algorithm is used?
Is my data sent to a server?
What is AES-GCM and why is it recommended?
Can I decrypt data encrypted with a different tool?
How strong is AES-256 encryption?
Can I encrypt a message to share with someone else?
Comments
More in Hashing & Crypto
- UUID Generator
- Hash Generator
- Password Generator
- Bcrypt Generator
- HMAC Generator
- Checksum Calculator
- MD5 Hash Generator
- SHA-256 Hash Generator
Comments