All guides

DEVOMNITOOLS / Developer guides

Encrypt and Decrypt Text with AES-256 in Your Browser (GCM & CBC)

Learn how 256-bit AES-GCM and AES-CBC encryption works locally via Web Crypto API. Master PBKDF2 key derivation, IV nonces, and OpenSSL commands with zero data leaks.

DevOmniTools Published: 3 min read
AES-256-GCM In-Browser WebCrypto Cryptographic Pipeline Architecture Diagram

Key takeaways

  • AES-GCM provides authenticated encryption with an integrity tag; AES-CBC only provides confidentiality.
  • Never reuse an Initialization Vector (IV) with the same cryptographic key.
  • Derive 256-bit keys from human passwords using PBKDF2 with at least 100,000 iterations.
  • 100% client-side WebCrypto execution eliminates server-side exposure risks.

Understanding 256-Bit Advanced Encryption Standard (AES)

The Advanced Encryption Standard (AES) is a symmetric block cipher standardized by NIST (FIPS 197). It processes data in 128-bit blocks using cryptographic keys of 128, 192, or 256 bits. In high-assurance environments, AES-256 represents the global gold standard for protecting data at rest and data in transit.

When developers need to encrypt text or decrypt text securely in web applications and backend systems, selecting the appropriate block cipher mode is critical to ensure both data integrity and confidentiality.

AES-256-GCM In-Browser WebCrypto Cryptographic Pipeline Architecture Diagram

Block Cipher Modes: AES-GCM vs. AES-CBC

The two most common modes for symmetric encryption are Galois/Counter Mode (GCM) and Cipher Block Chaining (CBC):

  1. AES-GCM (Authenticated Encryption with Associated Data - AEAD):

    • Combines Counter mode (CTR) with Galois field authentication.
    • Generates a 128-bit authentication tag alongside ciphertext.
    • Detects any ciphertext tampering or bit-flipping prior to decryption.
    • Recommended default for all modern web, API, and cloud architectures.
  2. AES-CBC (Cipher Block Chaining):

    • Chains the previous ciphertext block into the next plaintext block using XOR operations.
    • Requires PKCS#7 padding to align input data to 16-byte boundaries.
    • Susceptible to padding oracle attacks if error messages expose padding validity.
    • Maintained primarily for legacy system interoperability (such as older OpenSSL scripts or enterprise Java backends).

In-Browser Cryptographic Processing & Live Tool

You can test and execute authenticated encryption directly using the AES-256 online tool. The tool relies exclusively on the browser’s native Web Crypto API (window.crypto.subtle), ensuring that plaintexts, passphrases, and derived keys never leave client-side device memory.

When generating API tokens or random passwords to pair with AES encryption, verify entropy using the token generator or inspect token claims with the JWT decoder.

Key Derivation Architecture: PBKDF2

Human-entered passphrases lack the required 256 bits of cryptographic entropy. To transform a text password into a secure 256-bit AES key:

  • Salt Generation: A cryptographically secure random 16-byte salt is generated per operation via crypto.getRandomValues().
  • Iteration Count: 100,000 iterations of HMAC-SHA256 slow down offline dictionary and brute-force GPU attacks.
  • Key Extraction: A 32-byte (256-bit) raw key is derived and imported as AES-GCM or AES-CBC.
// Web Crypto API PBKDF2 key derivation example
const baseKey = await crypto.subtle.importKey(
  "raw",
  new TextEncoder().encode(passphrase),
  "PBKDF2",
  false,
  ["deriveKey"]
);

const aesKey = await crypto.subtle.deriveKey(
  {
    name: "PBKDF2",
    salt: saltBuffer,
    iterations: 100000,
    hash: "SHA-256"
  },
  baseKey,
  { name: "AES-GCM", length: 256 },
  false,
  ["encrypt", "decrypt"]
);

OpenSSL CLI Interoperability & Text Decryption

To test or verify encrypted envelopes against local terminal environments, use OpenSSL:

# Decrypt AES-256-CBC ciphertext using OpenSSL
openssl enc -d -aes-256-cbc -in ciphertext.bin -out plaintext.txt -pbkdf2 -iter 100000

# Encrypt text using OpenSSL AES-256-GCM
openssl enc -aes-256-gcm -in plaintext.txt -out ciphertext.bin -pbkdf2 -iter 100000

Raw binary outputs can be inspected and converted using the Base64 encoder to inspect byte layouts.

Security Boundaries & Best Practices

  • Zero Server Uploads: DevOmniTools executes all cryptographic calculations in local browser memory.
  • Nonce/IV Uniqueness: The initialization vector must be fresh for every encrypted message. Reusing an IV with AES-GCM destroys authentication guarantees.
  • Memory Erasure: Browsers cannot guarantee deterministic zeroization of garbage-collected strings. Always close browser tabs after handling production keys.