Skip to content

AES Encryption / Decryption

Embed

Paste this where you want AES Encryption / Decryption on your site. Adjust the height to fit.

<iframe src="https://www.browserutils.dev/embed/encryption-decryption/" width="100%" height="500" frameborder="0" loading="lazy" title="AES Encryption / Decryption"></iframe>
<p style="font-size:12px;margin:4px 0 0"><a href="https://www.browserutils.dev/tools/encryption-decryption/">AES Encryption / Decryption</a> by BrowserUtils</p>

Encrypt and decrypt text with AES-GCM.Runs in this tab.

Mode:

Next step

About 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?
This tool uses AES-GCM (Galois/Counter Mode) with a 256-bit key derived from your password via PBKDF2. AES-GCM provides both confidentiality and authenticity.
Is my data sent to a server?
No. All encryption and decryption happens entirely in your browser using the Web Crypto API. Your data and password never leave your device.
What is AES-GCM and why is it recommended?
AES-GCM is an authenticated encryption mode that provides both confidentiality and integrity checking. It detects if encrypted data has been tampered with, unlike basic AES-CBC which only provides confidentiality.
Can I decrypt data encrypted with a different tool?
Only if the other tool uses the same algorithm (AES-256-GCM), key derivation method (PBKDF2), and encoding format. Different tools may use different parameters, making cross-tool decryption unreliable.
How strong is AES-256 encryption?
AES-256 is considered unbreakable with current technology. It would take billions of years for the fastest supercomputers to brute-force a 256-bit key. The strength of your encrypted data depends primarily on the password you choose.
Can I encrypt a message to share with someone else?
Yes, encrypt your message with a password and share the encrypted output. The recipient can decrypt it using the same password on this same tool. Share the password through a separate secure channel.

More in Hashing & Crypto

All 15 hashing & crypto