User Tools

Site Tools


tips:checksums

Checksums

Checksums are (hopefully) uniquely generated strings derived from applying a hash function to all of the data in a particular file. Common hash algorithms include MD5, SHA1, SHA256, and SHA512. A typical use case of a checksum is in the verification of downloaded files. A person hosting a file on the internet will often provide the checksum string for which a user can cross check with their own copy of the file. This is used to verify that the data has not been tampered with and that no data corruption has occurred during the transfer.

Generating a Checksum

Linux

Linux makes it very simple and straightforward to generate hashes. The syntax is as follows:

$ <algorithm>sum <file>

Examples:
Print to tty session

$ md5sum .bashrc
44478f3f5928690793b8882d0cb310cf *.bashrc

Print to file

$ sha256sum .bashrc > .bashrc.sha256

Windows

Windows, as always, is some horribly unmemorable syntax.

C:\> certutil -hashfile <file> <algorithm>

Example

C:\> certutil -hashfile .\mpv-shot0001.jpg SHA256
SHA256 hash of .\mpv-shot0001.jpg:
f70965aeb05a85a464471ac000676262701dc88d7dce969e2a1997ef7f72ee2e
CertUtil: -hashfile command completed successfully.

Verifying a Checksum

Linux

$ sha256sum -c <file>.sha256 < <file>

Example

$ sha256sum -c test.txt.sha256 < test.txt
test.txt: OK

Windows

Use your eyes to read each character to verify that the two hashes are the same, or use cygwin.

tips/checksums.txt · Last modified: 2021/06/18 16:36 by 127.0.0.1