Skip to content

Symmetric Encryption

Medium — good to knowSecurity

ELI5 — The Vibe Check

Symmetric encryption uses the same key to lock and unlock data. Like a house key — whoever has a copy can both lock and unlock the door. Super fast, but the challenge is: how do you share the key securely? That's why asymmetric encryption is used first, then symmetric takes over for speed.

Real Talk

Symmetric encryption uses a single shared key for both encryption and decryption. It's computationally faster than asymmetric encryption, making it suitable for bulk data. The key distribution problem is typically solved by exchanging keys via asymmetric encryption. Common algorithms: AES-256, ChaCha20.

Show Me The Code

import { createCipheriv, createDecipheriv, randomBytes } from 'crypto';

const key = randomBytes(32); // 256-bit AES key
const iv = randomBytes(16);

const encrypt = (text) => {
  const cipher = createCipheriv('aes-256-gcm', key, iv);
  return Buffer.concat([cipher.update(text), cipher.final()]);
};

When You'll Hear This

"AES-256 is the symmetric encryption standard we use for stored data." / "After the TLS handshake, symmetric encryption handles the rest."

Made with passive-aggressive love by manoga.digital. Powered by Claude.