By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Hashing is a one-way cryptographic function that converts any input (file, password, message) into a fixed-length string of characters (the "hash" or "digest"). Unlike encryption, hashing is irreversible—you can’t retrieve the original data from the hash. Its primary purpose is integrity verification (ensuring data hasn’t been altered) and authentication (e.g., password storage, digital signatures). A real-world example: In 2012, LinkedIn suffered a breach where 6.5 million unsalted SHA-1 password hashes were leaked. Attackers cracked them using rainbow tables, exposing plaintext passwords. This incident highlights why weak hashing (like MD5 or unsalted SHA-1) is dangerous.
Standards: NIST SP 800-107 (SHA), FIPS 180-4 (Secure Hash Standard).
Message Digest: Another term for a hash output. Used interchangeably with "hash value."
SHA (Secure Hash Algorithm): A family of NIST-approved hash functions. Variants:
SHA-3: Latest NIST standard (2015), based on the Keccak algorithm. Not yet widely adopted.
MD5 (Message Digest Algorithm 5): 128-bit hash. Broken—prone to collisions (e.g., Flame malware used MD5 collisions to forge certificates). Still seen in legacy systems but never use for security.
HMAC (Hash-Based Message Authentication Code): Combines a hash function (e.g., SHA-256) with a secret key to provide integrity + authenticity. Used in TLS, IPsec, and API authentication.
HMAC-SHA256(key, message)
Standard: RFC 2104.
Salt: Random data added to an input (e.g., a password) before hashing to prevent rainbow table attacks. Stored alongside the hash.
hash(password + salt)
Best Practice: Use a unique salt per user (NIST SP 800-63B).
Pepper: A secret value added to the input (like salt) but not stored with the hash. Used to slow down brute-force attacks.
Example: hash(password + salt + pepper).
hash(password + salt + pepper)
Collision: When two different inputs produce the same hash. Collision resistance is a key property of secure hash functions.
Attack Example: Birthday Attack (exploits probability to find collisions faster).
Preimage Resistance: Hard to reverse a hash to find the original input. Second-preimage resistance means given input1, it’s hard to find input2 where hash(input1) = hash(input2).
input1
input2
hash(input1) = hash(input2)
Rainbow Table: A precomputed table of hashes and their plaintext inputs. Used to crack unsalted hashes quickly.
Defense: Use salting and slow hashing (e.g., bcrypt, Argon2).
Digital Signature: A hash of a message encrypted with a private key. Proves authenticity + integrity (e.g., code signing, TLS certificates).
❌ Never use MD5 or SHA-1 for security.
Add Salt (and Pepper if Possible)
Example (Python): python import os, hashlib salt = os.urandom(16) # 16-byte random salt password = b"my_secure_password" hash = hashlib.pbkdf2_hmac('sha256', password, salt, 100000)
python import os, hashlib salt = os.urandom(16) # 16-byte random salt password = b"my_secure_password" hash = hashlib.pbkdf2_hmac('sha256', password, salt, 100000)
Store Hashes Securely
Use parameterized queries to prevent SQL injection (e.g., when saving hashes to a database).
Verify Integrity
sha256sum file.txt
For passwords: Hash the input + stored salt, then compare with the stored hash.
Monitor for Weaknesses
Rotate keys if using HMAC (e.g., every 1–2 years).
Respond to Breaches
os.urandom()
D) SHA-256 is vulnerable to collisions. Answer: B) Rainbow table attacks can crack passwords. Explanation: Unsalted hashes are vulnerable to precomputed rainbow tables, even if SHA-256 is used.
Which of the following provides both integrity and authenticity for a message?
D) RSA Answer: C) HMAC-SHA256. Explanation: HMAC combines a hash function with a secret key to ensure the message hasn’t been altered (integrity) and comes from a trusted source (authenticity).
During a penetration test, an attacker finds two different files with the same MD5 hash. What type of attack is this?
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.