Calculating checksums of files

Checksums are short, fixed-length strings that can be calculated from arbitrarily large inputs. They are commonly used to validate the contents of files, as the checksum will change considerably even with minimal changes to the input. More information can be found on Wikipedia.

The commands for calculating checksums are very similar on Linux and macOS. Both platforms use the same command for SHA-256 checksums, but Linux uses the md5sum command for MD5 checksums, while macOS uses md5.

# Calculate MD5 checksum on Linux
md5sum <my-file> <my-encrypted-file>.c4gh
# ... and on macOS
md5 <my-file> <my-encrypted-file>.c4gh
# The SHA-256 checksum command is the same on both platforms
shasum -a 256 <my-file> <my-encrypted-file>.c4gh

The results can be written to a file using the > operator:

For example:

md5sum <my-file> <my-encrypted-file>.c4gh > <my-files>.md5
Note

We couldn’t find a Windows computer to test on, so please tell us if these instructions don’t work anymore.

Windows includes the certutil command, which can calculate file checksums directly in Command Prompt.

Calculate the MD5 checksum for each file with:

certutil -hashfile <my-file> MD5

and the SHA-256 checksum with:

certutil -hashfile <my-file> SHA256

To write the output to a file, use the same > operator as on Linux and macOS:

certutil -hashfile <my-file> MD5 > <my-file>.md5