What is the difference between Symmetric Encryption (AES) and Asymmetric Encryption (RSA/ECC)?
❓ Interview Prompt: Compare Symmetric Encryption (shared key, AES-256, fast bulk data) vs Asymmetric Encryption (public/private key pair, RSA/ECC, key exchange).
Encryption protects data confidentiality by transforming plaintext into ciphertext:
| Feature | Symmetric Encryption (AES-256-GCM) | Asymmetric Encryption (RSA / ECC) |
|---|---|---|
| Keys | Single shared secret key for encryption & decryption | Public Key (encrypts) + Private Key (decrypts) |
| Speed | Extremely fast (hardware SIMD accelerated) | Slower (computationally expensive math) |
| Use Case | Bulk data storage encryption & TLS payload session stream | Key exchange, digital signatures, JWT signing |
| Key Sharing | Key must be shared securely beforehand | Public key shared freely; Private key kept secret |
Code Implementation Example
import crypto from 'crypto';
// Symmetric AES-256-GCM Encryption
const key = crypto.randomBytes(32);
const iv = crypto.randomBytes(12);
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
let encrypted = cipher.update('Sensitive Payload', 'utf8', 'hex');
encrypted += cipher.final('hex');
const authTag = cipher.getAuthTag().toString('hex');Symmetric encryption (AES) uses one shared key for fast bulk data; asymmetric (RSA/ECC) uses public/private key pairs for key exchange.