Encryption is the mathematical machinery behind almost every security guarantee you rely on: HTTPS, password managers, disk encryption, signed software updates. You do not need to be a cryptographer to use it well, but you do need to know which tool fits which job. This lesson compares the two great families, symmetric and asymmetric encryption, and shows how real systems combine them.
Symmetric encryption uses one shared secret key for both encryption and decryption. The standard algorithm today is AES (Advanced Encryption Standard), typically AES-256, which is extremely fast, hardware-accelerated on modern CPUs, and considered secure against any known attack when used correctly.
Strengths:
The catch is key distribution: both parties must somehow share the secret first, and if you could already share secrets safely, you would not need encryption. Symmetric encryption alone also does not tell you who you are talking to.
Always use an authenticated mode such as AES-GCM, which detects tampering, and never reuse a nonce with the same key:
// AES-256-GCM encryption in Node.js (authenticated encryption)
const crypto = require('crypto');
function encrypt(plaintext, key) {
const iv = crypto.randomBytes(12); // unique nonce every time
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
const ciphertext = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);
const tag = cipher.getAuthTag(); // integrity check
return { iv, ciphertext, tag };
}
function decrypt({ iv, ciphertext, tag }, key) {
const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv);
decipher.setAuthTag(tag); // throws if data was tampered
return Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString('utf8');
}Asymmetric (public-key) cryptography uses a mathematically linked key pair: a public key you share with the world and a private key you guard. Data encrypted with the public key can only be decrypted with the private key. Common algorithms are RSA and elliptic-curve schemes such as ECDH and Ed25519.
This solves key distribution: anyone can encrypt a message to you using your public key, with no prior shared secret. Reversing the roles gives digital signatures: you sign with your private key, and anyone can verify with your public key that the message came from you and was not altered. Signatures power TLS certificates, signed git commits, JWT tokens and software update verification.
The costs: asymmetric operations are hundreds of times slower than AES and work on small payloads, so nobody encrypts large files with RSA directly.
Real protocols combine the families. TLS, PGP and modern messaging apps all follow the same pattern:
TLS 1.3 additionally uses ephemeral keys per session, giving forward secrecy: even if a server's long-term private key leaks later, past recorded traffic cannot be decrypted.
A quick distinction that trips up beginners: hashes (SHA-256, bcrypt) are one-way and have no key; you can never get the input back. Encryption is two-way by design. Use hashing for integrity checks and password storage, encryption for data you need to read again.
Next lesson: Understanding SQL Injection and How to Prevent It, our first deep dive into an application-level attack.