Verify a checksum on Windows, macOS and Linux
:: Windows Command Prompt
certutil -hashfile ubuntu.iso SHA256
# Windows PowerShell
Get-FileHash ubuntu.iso -Algorithm SHA256
# macOS
shasum -a 256 ubuntu.iso
# Linux
sha256sum ubuntu.iso
sha256sum -c SHA256SUMS # checks every file listed
Compare the full value, not just the first and last few characters. Case does not matter: ABC123 and abc123 are the same hex value.
Hash lengths at a glance
- CRC32: 32 bits, 8 hex characters.
- MD5: 128 bits, 32 hex characters.
- SHA-1: 160 bits, 40 hex characters.
- SHA-256 and SHA3-256: 256 bits, 64 hex characters.
- SHA-512: 512 bits, 128 hex characters.
The length of a published checksum tells you which algorithm to pick. A 64-character value is almost always SHA-256.
Known hashes to test your code
The text hello, in lowercase with no newline, always gives these values:
MD5 5d41402abc4b2a76b9719d911017c592
SHA-256 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
On the command line, use echo -n hello | sha256sum. Without -n, echo adds a newline and you get a completely different hash.
Hashing is not encryption
Encryption is meant to be undone by someone with the key. A hash cannot be undone by anyone, which is the point. So a hash is right for checking files and for storing passwords (with a slow algorithm such as bcrypt or Argon2), but wrong for anything you need to read back later, such as a stored API key or a message. For a hash that proves who sent a message, use an HMAC with a shared secret.