Concept Focus
Word origin: crypto = secret; graphy = the science of writing. Definition: the science of transforming plaintext (PT) into ciphertext (CT) to achieve confidentiality, integrity, and authenticity, and non-repudiation when signed.
- Symmetric encryption: the same key for encrypt and decrypt; fast for bulk data. Example: AES.
- Asymmetric encryption: a public / private key pair; public encrypts, private decrypts. Examples: RSA, ECC.
- Algorithm: the deterministic rules. Key: a secret value that drives the algorithm.
Encoding vs Encryption
- Encoding (character-level; usability and compatibility like ASCII or Base64): not a security control.
- Encryption (binary-level; security): transforms PT into CT and requires a key to decrypt.
Symmetric Encryption
A single secret key (K) is used for both encryption and decryption, optimized for speed and bulk data (backup files, object storage, logs, telemetry). It is implemented as block ciphers (e.g., AES: fixed-size blocks, padding, modes) or stream ciphers (bit or byte at a time).
Why it's fast. The operations (substitution, permutation, XOR, finite-field math) are constant-time and hardware-accelerable (AES-NI), with no expensive big-integer math per message like RSA.
Critical moving parts.
- Key (K): high entropy, KDF / PRNG generated, stored in KMS / HSM, rotated.
- IV / Nonce: uniqueness prevents pattern leakage (CTR / GCM requires a never-reused nonce per key).
- Mode of operation: ECB (pattern leaks, avoid), CBC (needs a random IV; error propagation), CTR (nonce + counter; parallelizable), GCM (AEAD: adds integrity via an authentication tag).
- Padding: for block alignment (PKCS#7) when using block modes that require it.
How symmetric encryption works
- 1. Key generation. A secure key is generated using algorithms like PBKDF2 or hardware random number generators, then shared or transferred securely. Example: a 256-bit AES key as a 32-byte hexadecimal string.
- 2. Encryption. The plaintext is processed in blocks or streams using the algorithm and the secret key. Example: AES-256 in CBC mode encrypts a 128-bit block with the key and an initialization vector (IV) to produce ciphertext.
- 3. Transfer of ciphertext. The encrypted message is sent over the network. Even if intercepted, it stays unreadable without the shared secret key and the algorithm.
- 4. Decryption. The recipient uses the same secret key and the reverse algorithm to convert the ciphertext back to plaintext.
Key reuse across environments. IV / nonce reuse (catastrophic in CTR / GCM). Storing keys in code or CI variables. ECB for structured data such as images or JSON with repeated fields.
Symmetric algorithms
Asymmetric Encryption
Two mathematically related keys: a Public key (Pub) and a Private key (Priv).
- Confidentiality mode: encrypt with the recipient's Pub, decrypt with the recipient's Priv.
- Authentication / signature mode: sign with the sender's Priv (over a hash), verify with the sender's Pub.
- Algorithms: RSA (factoring hardness), ECC (elliptic-curve discrete log), ElGamal (bigger ciphertexts), DH / ECDH (key exchange only).
Strengths. Solves key distribution (no sharing of the private key) and enables digital signatures, certificates, and PKI. Trade-offs. Slower than symmetric for bulk data, so it is used to exchange a session key (hybrid); it requires PKI (CAs, CRLs / OCSP) to vouch for public keys; and it carries side-channel risks (timing attacks on RSA), so use constant-time libraries or an HSM.
How asymmetric encryption works
- 1. Key pair generation. A public key (shared openly) and a private key (kept secret) are generated.
- 2. Encryption. The sender uses the recipient's public key to convert the message into ciphertext.
- 3. Transmission. The ciphertext is sent over the network; if intercepted, it stays unreadable without the private key.
- 4. Decryption. The recipient uses their private key to decrypt.
- 5. Verification (digital signature). The sender may sign with their private key; the recipient verifies with the sender's public key, confirming authenticity and integrity.
- 6. Result. The message returns to plaintext, with confidentiality from the recipient's key pair and integrity and authenticity from the signature.
Asymmetric encryption and the CIA triad
- Confidentiality. If Anya sends a payroll file to Marcus, she encrypts it with Marcus's public key; only his private key can decrypt it. Example: PGP for secure email.
- Integrity. Marcus creates a digital signature by hashing the file and encrypting the hash with his private key; Anya verifies with his public key, and a single changed bit fails the check. Example: code signing for software updates.
- Availability (indirectly). By supporting TLS handshakes, it enables secure sessions for banking, HR portals, and test dashboards. It doesn't guarantee uptime, but it builds trustworthy channels that prevent denial-of-service via impersonation. Example: HTTPS certificates.
Anya encrypts test logs with Anas's public key for confidentiality. Anas signs his response with his private key for integrity. Both rely on TLS for their collaboration tools to stay available.
Brain Ticklers
Q1. Anya needs to encrypt a 5 GB log file before uploading it to Neuromesh's storage. Which method is most efficient?
- Asymmetric encryption (RSA) with a 2048-bit key
- Symmetric encryption (AES-256) with shared key K1
- Encoding with Base64 before upload
- Signing with Neuromesh's private key
Q2. Marcus tells Anya to “never email a symmetric key over the internet.” Why?
- Keys can only be exchanged in Base64 format
- If the symmetric key is intercepted, the entire system is compromised
- Symmetric keys regenerate automatically, so distribution is irrelevant
- Asymmetric encryption does not require keys at all
Q3. In an Alice to Bob exchange, why can't Mallory use Bob's public key to decrypt the ciphertext?
- Public keys are designed for decryption only
- Mallory intercepted the ciphertext incorrectly
- Public keys can only encrypt; private keys are required to decrypt
- Mallory needs Anya's public key instead
Q4. Neuromesh wants both confidentiality and authentication in their API communication. Which combination is correct?
- Encrypt with Bob's private key, decrypt with Bob's public key
- Encrypt with Bob's public key (confidentiality), sign with Anya's private key (authentication)
- Encrypt with Base64, verify with SHA-1
- Encrypt with AES, publish the AES key on a public repo
