.env · security

AES-256 Key Generator

Generate a cryptographically strong 256-bit AES key for AES-256-GCM or AES-256-CBC encryption. Hex or base64, generated in-browser — nothing is uploaded.

Be the first to rate
AES-256 encryption key (32 bytes)
256-bit key for AES-256-GCM / AES-256-CBC
Raw key
.env line
ENCRYPTION_KEY=
Usage (Node.js crypto)
const key = Buffer.from(process.env.ENCRYPTION_KEY!, 'hex'); // 32 bytes

What it does

  • 256-bit (32 byte) key in hex or base64
  • Matches Node's crypto.randomBytes(32).toString('hex'|'base64')
  • Runs entirely in-browser with crypto.getRandomValues
  • One-click copy of raw key or full ENCRYPTION_KEY=… .env line

Privacy

Runs 100% in your browser. Your .env never touches our servers.

client-side only

When to use this tool

  • Encrypting sensitive fields in a database with AES-256-GCM
  • Setting up application-level encryption for uploaded files
  • Generating a key for encrypting .env values or config secrets
  • Rotating a key that may have been exposed in logs or backups

Common mistakes

  • Deriving the key from a short password instead of using full 32 bytes of randomness
  • Reusing the same IV/nonce across multiple encryptions with the same key
  • Storing the encryption key in the same database as the data it encrypts
  • Using AES-256-ECB (no IV, deterministic) instead of GCM or CBC

What is an AES-256 key?

AES-256 is a symmetric encryption algorithm — the same 256-bit key both encrypts and decrypts data. The key must come from a cryptographically secure random source; deriving it from a password or predictable string defeats the purpose of a 256-bit key space.

Using it in Node.js

import { createCipheriv, randomBytes } from 'crypto';

const key = Buffer.from(process.env.ENCRYPTION_KEY!, 'hex'); // 32 bytes
const iv = randomBytes(12); // fresh IV per encryption, GCM recommends 12 bytes

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

Key management basics

  • Store the key in a secrets manager or environment variable — never alongside the encrypted data.
  • Generate a new, unpredictable IV for every encryption operation; never reuse an IV with the same key.
  • Rotate the key periodically and after any suspected exposure, re-encrypting existing data under the new key.

Frequently asked questions

Why 32 bytes for an 'AES-256' key?

AES-256 uses a 256-bit key, and 256 bits = 32 bytes. That's true regardless of encoding — 32 bytes is 64 hex characters or roughly 44 base64 characters (with padding).

Should I use hex or base64?

Both encode the same amount of entropy. Hex is easier to eyeball and debug; base64 is more compact and common in JWT/JOSE contexts. Node's crypto.randomBytes(32).toString('hex') and .toString('base64') both work directly with this key.

Do I need a separate IV/nonce?

Yes. AES-256-GCM and AES-256-CBC both require a unique initialization vector (IV) per encryption operation, generated fresh each time — never reused with the same key. This tool generates the key only; generate a random IV per-message in your encryption code.

Is this the same as an AUTH_SECRET or JWT signing key?

No — signing keys (HMAC secrets) authenticate that data wasn't tampered with, while an AES key encrypts data so it can't be read without the key. Both are 32-byte random values, but they serve different purposes and shouldn't be reused for both roles.

Related tools

coming soon

Get notified when env syncing launches

We're building a tiny tool to keep .env files in sync across teammates and environments. Leave your email — no spam, just a single launch ping.