Skip to content

Hashing Functions

Hashing is a one-way cryptographic function that converts input data of any size into a fixed-length output (hash). Unlike encryption, hashing is irreversible - you cannot retrieve the original data from the hash.

Not reviewedNo review date recorded2 scriptsEdit this page on GitHub
On this page

After this lesson you can

  • Explain what Hashing Functions is in your own words.
  • Describe how the attack or technique works.
  • Apply the prevention methods described here.
  • Read and run the 2 Python scripts in a lab you control.

Overview

Hashing is a one-way cryptographic function that converts input data of any size into a fixed-length output (hash). Unlike encryption, hashing is irreversible - you cannot retrieve the original data from the hash.

Common Use Cases

1. Password Storage

  • Store hashes instead of plaintext passwords
  • Add salt to prevent rainbow table attacks
  • Use slow hashes (bcrypt, Argon2) for passwords

2. Data Integrity

  • Verify files haven't been tampered with
  • Compare hashes before/after transfer
  • Detect corruption or unauthorized changes

3. Digital Signatures

  • Hash the message, then sign the hash
  • More efficient than signing entire message

4. Blockchain / Merkle Trees

  • Link blocks in blockchain
  • Verify transaction integrity

Hash Algorithm Comparison

AlgorithmHash SizeSpeedSecurityUse Case
MD5128 bitsVery Fast❌ BrokenLegacy only
SHA-1160 bitsFast❌ WeakLegacy only
SHA-256256 bitsModerate✅ SecureGeneral purpose
SHA-3256-512 bitsModerate✅ SecureModern applications
bcryptVariableSlow✅ SecurePassword hashing
Argon2VariableSlow✅✅ Very SecurePassword hashing (winner of PHC)

Security Warnings

  • Never use MD5 or SHA-1 for security (collision attacks)
  • Always use salt for password hashing
  • Use key derivation functions (PBKDF2, bcrypt, Argon2) for passwords
  • Hash functions don't need keys - if it needs a key, it's a MAC

Best Practices

  1. For file integrity: SHA-256 or SHA-3
  2. For passwords: bcrypt, Argon2, or PBKDF2
  3. Add salt: Unique per password
  4. Use pepper: Additional secret stored separately
  5. Work factor: Make it computationally expensive

Practical Python labs

Open a script to read its source and copy the run commands. Run security tools only on systems you own or have written permission to test.

Check what you have covered

These questions are generated from this lesson's category, standards mapping and scripts. They test where things live in the guide, not how well you understand the concepts. Nothing is saved or tracked.

1.Which category is "Hashing Functions" part of?
2.Which of these scripts belongs to the "Hashing Functions" lesson?