Tutorial 1: Encryption, Hashing, and MACs

Unit 2 ยท Cryptography and key management

Objectives

Encryption is reversible with a key and protects confidentiality. Hashing is designed to be one-way and supports fingerprints, but a plain hash is not proof of origin. A message authentication code (MAC) uses a shared secret to provide integrity and authenticity to parties that share that secret.

ciphertext = Encrypt(key, plaintext)
digest = Hash(file)
tag = MAC(sharedSecret, message)
passwordRecord = SlowHash(password, uniqueSalt)

Use reviewed libraries and authenticated encryption modes such as AES-GCM or ChaCha20-Poly1305. Do not invent algorithms or reuse nonces. Password storage needs a memory- or CPU-hard password hashing function, unique salts, rate limiting, and recovery controls.

Exercises

  1. Choose encryption, hashing, or MAC for four security requirements.
  2. Explain why a public hash cannot authenticate an API response.
  3. List the fields needed to verify authenticated encryption.

Self-check

  1. Which primitive is reversible?
  2. What does a salt prevent?
  3. What does a MAC key provide?

Self-Check Quiz

1. What does authenticated encryption provide?

AnswerConfidentiality plus integrity and authenticity for the ciphertext and associated data.

2. Should passwords be encrypted for storage?

AnswerNormally no. Store a salted, slow password-hash verification record rather than a reversible password.

Homework

  1. Design credential storage for an enterprise portal.
  2. Specify an authenticated-encryption envelope for a stored document.
  3. Explain nonce uniqueness and password-rate limiting.
Sample answerA sound design uses a password-hashing function with a unique random salt and tuned cost, plus MFA and rate limits. Documents use authenticated encryption with a unique nonce, stored key identifier, ciphertext, and authentication tag. Keys are protected separately from data.