Hashing and Data Integrity
Learn how SHA-256, MD5, and HMAC produce fixed-length digests that verify data has not been altered in transit or storage.
What Is a Hash Function?
A cryptographic hash function is a mathematical algorithm that takes an input of any size and produces a fixed-length output called a hash, digest, or fingerprint. Hash functions are one-directional: given a hash, it should be computationally infeasible to determine the original input. They are deterministic: the same input always produces the same hash. Hash functions are the foundation of data integrity verification, digital signatures, password storage, and many other security mechanisms.
Properties of Secure Hash Functions
A secure cryptographic hash function must have four key properties. Pre-image resistance: given a hash output, it's computationally infeasible to find any input that produces it. Second pre-image resistance: given an input, it's infeasible to find a different input with the same hash. Collision resistance: it's infeasible to find any two different inputs that produce the same hash output. Avalanche effect: changing even a single bit of input causes a completely different hash output, making tampering detectable.
# Avalanche effect demonstration
echo -n 'Hello' | sha256sum
# 185f8db32... (completely different when one char changes)
echo -n 'Hello!' | sha256sum
# 334d016f7... (entirely different hash)
# Same input ALWAYS produces same hash (deterministic)
echo -n 'Security+' | sha256sum
echo -n 'Security+' | sha256sum
# Both outputs are identicalAll lessons in this course
- Symmetric Encryption Algorithms
- Asymmetric Encryption and Key Pairs
- Hashing and Data Integrity
- Key Exchange and Hybrid Encryption