A cryptographic hash function takes arbitrary input—like a password, message, or file—and produces a fixed-length digest. The key idea is that it’s a one-way function: easy to compute, but computationally infeasible to reverse.”

“From a security perspective, good hash functions are deterministic, collision-resistant, and have the avalanche effect—so even a one-character change completely changes the output.”

“In practice, older algorithms like MD5 and SHA-1 are broken due to collision attacks, so today we rely on SHA-256 or SHA-512 from the SHA-2 family.”

“One important distinction is that hashing is not encryption. Hashing is one-way and is used for integrity and authentication, while encryption is reversible and used for confidentiality.”

“For passwords specifically, we don’t use raw SHA-256 or SHA-512 because they’re too fast. Instead, we use dedicated password-hashing algorithms like bcrypt, scrypt, or Argon2, which are intentionally slow and salted to resist brute-force and rainbow-table attacks.”

“So overall, hashes are about verifying data hasn’t changed and proving knowledge of a secret, not about hiding data


Cryptographic Hash Functions — Senior Interview Notes

What is a cryptographic hash?

A cryptographic hash function maps any input (text, file, password) to a fixed-length output called a hash/digest.

Mental model:

👉 A one-way fingerprint for data.


Core properties (must-know)

A secure hash function is:

  1. Deterministic – same input → same hash
  2. Fixed output size – independent of input length
  3. Fast to compute – efficient for integrity checks
  4. Pre-image resistant – hash → original input is infeasible
  5. Collision resistant – hard to find two inputs with same hash
  6. Avalanche effect – tiny input change → totally different hash

Example:

"hello" → 2cf24dba...
"Hello" → 185f8db3...

Common hash algorithms (what to say in interviews)

MD5

  • 128-bit, very fast
  • Broken (collisions easy)
  • Use only for non-security checksums

SHA-1

  • 160-bit
  • Broken
  • Deprecated everywhere

SHA-256 (SHA-2)

  • 256-bit
  • Industry standard
  • Used in JWT, TLS, blockchain, API signing

SHA-512 (SHA-2)

  • 512-bit
  • Very strong
  • Faster on 64-bit systems

Quick comparison

AlgorithmOutputSecurityInterview Status
MD5128-bit❌ BrokenNever use
SHA-1160-bit❌ BrokenDeprecated
SHA-256256-bit✅ SecureRecommended
SHA-512512-bit✅ SecureRecommended

Hashing vs Encryption (very important)

HashingEncryption
One-wayTwo-way
Cannot be reversedCan be decrypted
Passwords, integritySensitive data

Examples:

  • Passwords → hash
  • Credit cards → encrypt

Password hashing (senior-level clarity)

Never store passwords with raw SHA-256 / SHA-512

Use password-hashing algorithms instead:

  • bcrypt
  • scrypt
  • Argon2 ✅ (modern standard)

Why?

  • Slow by design
  • Salted
  • Resistant to brute-force & rainbow tables

One-line takeaway (perfect interview closer)

A cryptographic hash is a fast, one-way, collision-resistant fingerprint used for integrity and authentication—not secrecy.


🔐 JWT-Specific Explanation (Add-on Answer)

A JWT is Base64URL-encoded, which means it is readable by anyone who has the token.

“In JWTs, hashing is used as part of the digital signature, not for encrypting the payload.”

“A JWT has three parts: header, payload, and signature. The header and payload are Base64-encoded, not encrypted, meaning they’re readable.”

“The signature is created by hashing the header and payload together using an algorithm like HMAC-SHA256 (for symmetric keys) or RSA/ECDSA with SHA-256 (for asymmetric keys).”

“When the server receives a JWT, it recomputes the hash and compares it to the signature. If they match, we know the token hasn’t been tampered with and was issued by a trusted authority.”

“So hashing in JWTs provides integrity and authenticity, not confidentiality. If you need confidentiality, you’d use JWE instead of JWS.”


🎯 One-line JWT summary (great for closing)

JWT uses hashing for signature verification to ensure integrity and trust—not to hide data.