If you need to calculate a checksum, aka
cryptographic hash value or digital fingerprint, on a
Mac OS X
system, you can use the md5
command to calculate a MD5 checksum, which is equivalent to the
md5sum utility on Linux
systems, and the shasum
command to calculate Secure Hash Algorithms (SHA). The default value for
shasum, if no
algorithm is specified, is Secure Hash Algorithm 1 (SHA-1), but you can specify other
algorithms, such as
Secure Hash
Algorithm 2 (SHA-2), e.g. SHA-256, using the -a option. E.g.
-a 256 for SHA-256.
Below is an example of hash values calculated with md5 and shasum on an executable file for WinSCP 5.11.1, a program for a Microsoft Windows system that I wanted to check on a MacBook Pro laptop running OS X El Capitan.
$ md5 ~/Documents/Temp/WinSCP-5.11.1-Setup.exe MD5 (/Users/jdoe/Documents/Temp/WinSCP-5.11.1-Setup.exe) = 7fb1fe6417216f427a44e6fa04595da3 $ shasum ~/Documents/Temp/WinSCP-5.11.1-Setup.exe dc978e7bf749d382fa4e10f1ad80c033bbaeb5af /Users/jdoe/Documents/Temp/WinSCP-5.11.1-Setup.exe $ shasum -a 256 ~/Documents/Temp/WinSCP-5.11.1-Setup.exe caffb74241517cd6be9f7372f792ec820fd9f40a2ea1541ee087a020418fcf3c /Users/jdoe/Documents/Temp/WinSCP-5.11.1-Setup.exe $
You can see usage information for the shasum programm by typing
shasum --help or checking the
man page with man
shasum.
$ shasum --help
Usage: shasum [OPTION]... [FILE]...
Print or check SHA checksums.
With no FILE, or when FILE is -, read standard input.
-a, --algorithm 1 (default), 224, 256, 384, 512, 512224, 512256
-b, --binary read in binary mode
-c, --check read SHA sums from the FILEs and check them
-t, --text read in text mode (default)
-p, --portable read in portable mode
produces same digest on Windows/Unix/Mac
-0, --01 read in BITS mode
ASCII '0' interpreted as 0-bit,
ASCII '1' interpreted as 1-bit,
all other characters ignored
The following two options are useful only when verifying checksums:
-s, --status don't output anything, status code shows success
-w, --warn warn about improperly formatted checksum lines
-h, --help display this help and exit
-v, --version output version information and exit
When verifying SHA-512/224 or SHA-512/256 checksums, indicate the
algorithm explicitly using the -a option, e.g.
shasum -a 512224 -c checksumfile
The sums are computed as described in FIPS-180-4. When checking, the
input should be a former output of this program. The default mode is to
print a line with checksum, a character indicating type (`*' for binary,
` ' for text, `?' for portable, `^' for BITS), and name for each FILE.
Report shasum bugs to mshelor@cpan.org
$