Symmetric and asymmetric encryption
Symmetric encryption uses a single shared key to both encrypt and decrypt. Both the sender and the recipient must have the same key, which creates the key distribution problem: how do you securely share the key in the first place? Symmetric algorithms are fast and well-suited for encrypting large amounts of data. AES (Advanced Encryption Standard) is the dominant symmetric algorithm, available in 128, 192, and 256-bit key lengths. AES-256 is the standard for protecting classified government data.
Asymmetric encryption uses a mathematically linked key pair: a public key and a private key. Data encrypted with one key can only be decrypted by the other. RSA and ECC (Elliptic Curve Cryptography) are the primary asymmetric algorithms. Asymmetric encryption is significantly slower than symmetric and is not practical for encrypting large data directly. In practice, asymmetric encryption is used to securely exchange a symmetric session key, and then symmetric encryption handles the bulk data.
This hybrid approach is exactly how TLS works. The TLS handshake uses asymmetric cryptography to authenticate the server and establish a shared session key. After the handshake, all data flows encrypted with a fast symmetric algorithm using that session key.
Hashing and its role in security
A hash function takes any input and produces a fixed-length output called a hash or digest. SHA-256 always produces a 256-bit output regardless of whether the input is a single character or a 10 GB file. Two different inputs cannot produce the same hash (collision resistance), and knowing the hash tells you nothing useful about the input (pre-image resistance). Hash functions are one-way: you cannot reverse a hash to recover the original data.
Hashing is used for integrity verification. Hash a file before and after transmission. If the hashes match, the file is unchanged. Password storage should use hashing, not encryption: store only the hash of the password, never the password itself. When a user logs in, hash what they typed and compare it against the stored hash. Adding a unique random value (a salt) before hashing prevents rainbow table attacks where precomputed hash tables map common passwords to their hashes.
MD5 and SHA-1 are cryptographically broken and should not be used for security purposes. SHA-256 and SHA-3 are current standards. HMAC (Hash-based Message Authentication Code) uses a hash function combined with a secret key to provide both integrity and authentication in a single operation.
Key lengths, modes, and how to choose the correct answer
Block ciphers like AES encrypt data in fixed-size blocks (128 bits for AES). The mode of operation determines how those blocks are chained. ECB (Electronic Codebook) mode encrypts each block independently and is insecure because identical plaintext blocks produce identical ciphertext blocks, leaking patterns. CBC (Cipher Block Chaining) XORs each block with the previous ciphertext block before encrypting, breaking the pattern. GCM (Galois/Counter Mode) provides both encryption and authentication in one operation and is the standard for TLS 1.3 and modern applications.
Stream ciphers encrypt data one bit or byte at a time instead of in blocks. RC4 was a widely used stream cipher that is now cryptographically broken. Modern alternatives are rarely stream ciphers in the traditional sense because AES in CTR or GCM mode effectively creates a stream cipher behavior from a block cipher.
Algorithm selection: bulk data encryption = AES-256. Key exchange or digital signatures = RSA or ECC (ECC achieves equivalent security with shorter keys). Integrity verification = SHA-256. Password storage = bcrypt, scrypt, or Argon2 (these are designed to be intentionally slow to defeat brute force). Broken and should never be used: MD5, SHA-1, DES, RC4.