What is a hash?
A hash is a fixed-size fingerprint of data. Learn its properties and where it is used.
A hash function turns any input, from one letter to a movie file, into a short fixed-length value called a hash or digest. Think of it as a fingerprint of the data.
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015adProperties of a good cryptographic hash
- Deterministic: the same input always gives the same hash.
- Fixed size: SHA-256 always produces 256 bits (64 hex characters), whatever the input.
- One-way: you cannot work backwards from the hash to the input.
- Avalanche effect: changing one bit of the input changes the hash completely.
- Collision resistant: it is infeasible to find two different inputs with the same hash.
Common algorithms
| Algorithm | Output | Status |
|---|---|---|
| MD5 | 128 bits | Broken for security. Collisions are easy. Fine only for non-security checksums. |
| SHA-1 | 160 bits | Broken for collision resistance. Avoid for new uses. |
| SHA-256, SHA-512 | 256 / 512 bits | Secure and widely used (SHA-2 family). |
| SHA-3 | variable | A newer standard built differently from SHA-2. |
What hashes are used for
- Integrity: check a file was not changed or corrupted.
- Digital signatures: sign the hash of a message instead of the whole message.
- Deduplication: identify identical files cheaply.
- Password storage: with special, slow hash functions (lesson 3).
NoteTry it: open the hash generator and type "abc", then "abd". One letter changes the whole output. That is the avalanche effect.
Test yourself
Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.