A cryptographic hash turns an arbitrary-length file, message, or video into a fixed-length digest. Hashing the same input repeats the same result, while a tiny input change can produce a completely different one. Security depends on making it difficult to recover an input, replace an input with another matching the digest, or find any two inputs with the same digest. section 2.1 section 2.7
The main security properties are:
- Pre-image resistance makes it infeasible to find an input that produced a given digest. section 2.7
- Second pre-image resistance makes it infeasible to find a different input matching the digest of a known input. section 2.1 section 2.7
- Collision resistance makes it infeasible to find two arbitrary inputs with the same digest. section 2.7
Checking a downloaded file
Hash the downloaded file with SHA-256, then compare the result with the digest published on the webpage. A match supports the claim that the file was not replaced. The published digest must itself be obtained securely; otherwise an attacker can replace both the file and its digest. section 2.1 section 2.4.4
$ openssl dgst -sha256 downloaded_file f63e68ac0bf052ae923c03f5b12aedc6cca49874c1c9b0ccf3f39b662d1f487b
Run the OpenSSL command to hash a downloaded file and compare its hexadecimal digest with the expected value. section 2.1
Digest size matters: a very short output makes collisions easy, so practical cryptographic hashes use substantially larger outputs. CRC32 detects some accidental errors but lacks these security properties; MD5 and SHA-1 are deprecated for secure use because published collisions broke their collision resistance. section 2.3 section 2.5
SHA-2 pads and divides input into blocks, then repeatedly feeds each block and the previous intermediate value into a compression function. SHA-3 instead uses a sponge: it absorbs padded input through a permutation and squeezes out the required digest. SHA-2 is unsuitable for hashing secrets because its construction permits length-extension attacks. section 2.5.1 section 2.5.2
Hashes support integrity or identity checks in several systems:
- Subresource integrity lets a browser hash an external JavaScript file before executing it. section 2.4.2
- BitTorrent hashes individual chunks so peers can verify pieces before reassembling a file. section 2.4.3
- Tor onion addresses can represent a hidden service’s public-key hash, helping authenticate the intended service. section 2.4.4



