AES-256-GCM/CBC Encrypt & Decrypt Online | OpenSSL Compatible

Encryption
100% client-side. Processed locally in your browser using the Web Crypto API. Nothing is sent to any server.
⚠️ Critical Security: Never reuse IV/nonces with the same key in GCM mode — it completely breaks authentication. Always use AES-256-GCM for new projects. Never use ECB mode — it leaks data patterns.

How It Works

What Is AES Encryption?

AES (Advanced Encryption Standard) is the world's most widely deployed symmetric encryption algorithm, standardized by NIST in 2001. It protects everything from HTTPS connections and messaging apps to disk encryption and secure backups. AES operates on 128-bit blocks using a series of transformation rounds (10/12/14 rounds for AES-128/192/256), applying four key operations: SubBytes (non-linear byte substitution), ShiftRows (row transposition), MixColumns (finite field multiplication), and AddRoundKey (XOR with round key). This design provides both confusion (complex relationship between key and ciphertext) and diffusion (each plaintext bit affects many ciphertext bits), making AES resistant to all known practical attacks.

AES-256, with its 2256 possible keys, offers a security margin that no foreseeable computing technology can brute-force — even quantum computers with Grover's algorithm would require 2128 operations, still computationally infeasible. It has been adopted by the U.S. government for Top Secret information, by TLS 1.3 for web traffic, and by countless open-source libraries.

Mode Selection Guide

ModeTypeAuthenticatedPaddingBest ForPerformance
Standard (GCM)Block + counterYes (GMAC tag)No (streaming)General-purpose, API payloads, TLS 1.3~10 GB/s (AES-NI)
CTRStream cipherNoNoLarge files, real-time streams, random access~10 GB/s (AES-NI)
OpenSSL CompatibleCBCNoPKCS7Interoperability with legacy tools~5 GB/s (AES-NI)
ECBBlock cipherNoPKCS7Never use — deterministic, leaks patterns~5 GB/s (AES-NI)

Which mode should you use? For 95% of use cases, choose AES-GCM — it provides authenticated encryption that detects tampering automatically. Use CTR only for very large data streams where padding overhead matters. Use OpenSSL Compatible mode only when you need to exchange encrypted data with legacy tools that expect the "Salted__" format. Never use ECB — it encrypts identical plaintext blocks to identical ciphertext blocks, leaking data patterns (the famous "ECB penguin" problem).

AES-128 vs AES-192 vs AES-256

VariantKey SizeRoundsSecurity LevelPerformanceUse Case
AES-128128 bits (16 bytes)10Sufficient for most applicationsFastest (baseline)General web traffic, non-sensitive data
AES-192192 bits (24 bytes)12Marginal benefit over 128~10% slowerRarely used in practice
AES-256256 bits (32 bytes)14Highest; future-proof vs Grover's~20% slowerCompliance (HIPAA, PCI-DSS, FIPS 140-3), disk encryption, classified data

Recommendation: Use AES-256 for all new projects — the 20% performance penalty is negligible on modern hardware with AES-NI acceleration, and you get the highest security margin. AES-128 remains perfectly secure for most applications, but AES-256 future-proofs against potential cryptanalytic breakthroughs.

Standards Compliance

  • Web Crypto API — W3C Recommendation (2017), supported by all modern browsers
  • NIST FIPS 197 — The official AES specification (2001)
  • NIST SP 800-38D — GCM mode specification (2012)
  • TLS 1.3 — RFC 8446 (2018), mandates AES-GCM as the preferred cipher suite
  • OpenSSL — Compatible with OpenSSL 1.1.1+ and LibreSSL 3.0+

Last updated:

Code Examples

Encrypt and decrypt with AES-256-GCM across multiple languages and platforms:

Browser — Web Crypto API (Hardware-Accelerated)

// AES-256-GCM encrypt with random IV and salt
const enc = new TextEncoder();
const key = await crypto.subtle.generateKey(
  { name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt']
);
const iv = crypto.getRandomValues(new Uint8Array(12));
const ciphertext = await crypto.subtle.encrypt(
  { name: 'AES-GCM', iv }, key, enc.encode('secret message')
);

// Export key for storage (JWK format)
const exported = await crypto.subtle.exportKey('jwk', key);
console.log('Key:', exported.k);
console.log('IV:', Array.from(iv).map(b => b.toString(16).padStart(2, '0')).join(''));

Python — PyCryptodome / cryptography

# AES-256-GCM with authenticated encryption
from Crypto.Cipher import AES
import os

key = os.urandom(32)  # 256-bit key
iv = os.urandom(12)   # 96-bit IV for GCM
cipher = AES.new(key, AES.MODE_GCM, nonce=iv)
ciphertext, tag = cipher.encrypt_and_digest(b'secret message')

print(f'Key: {key.hex()}')
print(f'IV: {iv.hex()}')
print(f'Ciphertext: {ciphertext.hex()}')
print(f'Tag: {tag.hex()}')

Go — crypto/aes + crypto/cipher

package main

import (
    "crypto/aes"
    "crypto/cipher"
    "crypto/rand"
    "fmt"
)

func main() {
    key := make([]byte, 32) // AES-256
    rand.Read(key)
    
    block, _ := aes.NewCipher(key)
    gcm, _ := cipher.NewGCM(block)
    
    nonce := make([]byte, gcm.NonceSize())
    rand.Read(nonce)
    
    ciphertext := gcm.Seal(nonce, nonce, []byte("secret message"), nil)
    fmt.Printf("Ciphertext: %x\n", ciphertext)
}

Rust — aes-gcm crate

use aes_gcm::{Aes256Gcm, Key, Nonce};
use aes_gcm::aead::{Aead, KeyInit, OsRng};
use rand::RngCore;

let key = Key::<Aes256Gcm>::generate(&mut OsRng);
let mut nonce_bytes = [0u8; 12];
OsRng.fill_bytes(&mut nonce_bytes);
let nonce = Nonce::from_slice(&nonce_bytes);

let cipher = Aes256Gcm::new(&key);
let ciphertext = cipher.encrypt(nonce, b"secret message".as_ref()).unwrap();

println!("Key: {:?}", key.as_slice());
println!("Nonce: {:?}", nonce_bytes);
println!("Ciphertext: {:?}", ciphertext);

Node.js — crypto module

const crypto = require('crypto');

const key = crypto.randomBytes(32); // AES-256
const iv = crypto.randomBytes(12);  // 96-bit IV for GCM

const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
const encrypted = Buffer.concat([cipher.update('secret message'), cipher.final()]);
const tag = cipher.getAuthTag();

console.log('Key:', key.toString('hex'));
console.log('IV:', iv.toString('hex'));
console.log('Ciphertext:', encrypted.toString('hex'));
console.log('Tag:', tag.toString('hex'));

Common Pitfalls & Attack Vectors

⚠️ IV/Nonce Reuse in GCM Mode — Reusing even a single IV with the same key completely breaks authentication and confidentiality. An attacker can recover the XOR of two plaintexts and forge valid ciphertexts. Real-world example: In 2016, researchers discovered that multiple Android apps reused AES-GCM nonces, allowing attackers to decrypt sensitive data. Always generate a fresh random IV for every encryption operation.
⚠️ Using ECB Mode — ECB encrypts identical plaintext blocks to identical ciphertext blocks, leaking data patterns. The famous "ECB penguin" image demonstrates how encrypting a bitmap of a penguin with ECB still reveals the penguin's shape. Never use ECB — use GCM or CTR instead.
⚠️ Weak or Hardcoded Keys — Deriving keys from passwords without a KDF, using predictable keys (timestamps, sequential counters), or hardcoding keys in source code are critical vulnerabilities. Use cryptographically secure random generators (crypto.getRandomValues, os.urandom) and store keys in environment variables or secret managers, never in code.
⚠️ Missing Authentication in CBC/CTR — CBC and CTR modes provide confidentiality but no integrity checking. Without authentication (e.g., HMAC-SHA256), attackers can modify ciphertext undetected, leading to padding oracle attacks. Always use authenticated encryption (GCM) or add a separate HMAC if using CBC/CTR.
⚠️ Insufficient Key Length — Using AES-128 for long-term storage or classified data may not provide adequate security margin against future cryptanalytic advances or quantum attacks. Use AES-256 for all new projects — the 20% performance penalty is negligible on modern hardware.
⚠️ Predictable IV Generation — Using sequential or static IVs (e.g., all zeros) breaks the security guarantees of CBC and GCM modes. Always use cryptographically random IVs — 12 bytes for GCM, 16 bytes for CBC.

Security Notes

🔒 Never reuse an IV with the same key in GCM mode — it completely breaks authentication and confidentiality.
🔒 Prefer GCM over CBC — CBC without authentication is vulnerable to padding oracle attacks; GCM detects tampering automatically.
🔒 Use unique passphrases per encryption task and store them separately from the ciphertext.
🔒 OpenSSL Compatible mode uses MD5 for key derivation — acceptable for interoperability but not recommended for new projects; use Standard mode instead.

Disclaimer

Disclaimer: This page is for educational and testing purposes only. It does not constitute professional security advice. For production use of cryptographic primitives (keys, certificates, JWT, TLS), consult official standards (NIST, IETF) and conduct a formal security review.

Further Reading & Standards

Related Concepts

Related Tools

Need a strong passphrase for your encryption key? The Passphrase Generator creates memorable, high-entropy passphrases. For key derivation with configurable parameters, the KDF Hash Generator supports PBKDF2, Argon2id, and Scrypt. For ChaCha20 (a modern alternative to AES), try the ChaCha20 Encrypt/Decrypt tool.

Frequently Asked Questions

What is the difference between Passphrase and Raw Key mode?

Passphrase mode derives an encryption key from your passphrase using PBKDF2 (100,000 iterations), making it easy to use — you only need to remember a password. Raw Key mode lets you provide the exact key bytes (in hex or text), giving you full control over the encryption key. Raw Key mode is useful for interoperability with other systems that use specific keys.

Should I use GCM, CTR, or OpenSSL Compatible mode?

Use Standard (AES-GCM) for most cases — it provides authenticated encryption that detects tampering. Use CTR for large data streams where padding overhead matters. Use OpenSSL Compatible only when you need to exchange encrypted data with tools that expect the OpenSSL "Salted__" format.

What key length should I choose?

AES-256 is recommended for all use cases — the performance difference vs AES-128 is negligible on modern hardware. AES-128 is still secure and slightly faster. AES-192 is rarely used in practice. All three are NIST-approved.

Can I use a custom Initialization Vector (IV)?

Yes. When using the Standard encryption method, open Advanced Options and switch the IV to "Custom IV". Enter a 24-character hex string (96 bits) to use a specific IV instead of a randomly generated one. This is useful for interoperability with other systems that require a fixed IV. The custom IV is embedded in the ciphertext output and automatically extracted during decryption.

Can I decrypt ciphertext from other tools?

Yes! This tool automatically detects and decrypts OpenSSL-format ciphertext (starting with "Salted__" prefix, commonly used by other online tools). For Standard format, use this tool for both encryption and decryption. If you need to share encrypted data with other tools, select "OpenSSL Compatible" format when encrypting.

Why does the same text produce different ciphertext each time?

A fresh random salt and IV are generated for every encryption operation. This is correct and intended — it ensures identical plaintext never produces identical ciphertext. Decryption still works because both the salt and IV are embedded in the output.

Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.

More in Encryption

Learn More