To check the sha1 of a file I would use
openssl sha1 <file> I'm not sure what to use to check the sha256 hash of the file however, what would you recommend?
You can use
openssl dgst -sha256 <file>
Tested on LibreSSL 2.6.4 on macOS 10.14 (Mojave).
Prior to Mojave you can use
openssl sha -sha256 <file> or
openssl sha256 <file>.
To check command line options for the openssl sha command:
openssl sha -help.
OS X ships with a shasum command.
> which shasum /usr/bin/shasum
You can use:
> shasum -a 256 <file>
> 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 email@example.com
shasum command ships with OSX for a while now. It will give same result as
openssl sha -sha256 when using
shasum using the
-a 256 option.
I would use this command.
shasum -a 256 -c <<<'paste hash to compare here *path to file goes here'
shasum -a 256 -c <<<,
followed by an optional space,
followed by a single tick (
followed by the hash to compare,
followed by a space,
followed by an asterisk (
followed by the path to the file,
followed by a closing single tick (
Like the following with delineating parens around the hash and filepath parts. (Don't include the parens in real life - they're just here to make the parts easy to see!)
shasum -a 256 -c <<< '(hashToCompare) *(filepath)'
The actual shasum command is
shasum -a 256 -c
shasumto use sha256.
shasumto "check" the provided input.
<<< is a Unix/Linux special character set, called a "redirection" operator. It's for feeding something into a prior command. By using it, we're saying we're going to provide a string of information for the
shasum command to use as input.
The string of input information must have opening and closing single ticks, such as
'some string here', or in this case, the hash and filepath to be checked.
The hash part inside the string doesn't need anything special - but it must be followed by a space.
The filepath part must begin with an asterisk (
*). This tells
shasumthat it's the file path part of the string.
So, here's a real-life example checking a particular MAMP download file against it's purported SHA-256 value:
shasum -a 256 -c <<< 'f05ede012b8a5d0e7c9cf17fee0fa1eb5cd8131f3c703ed14ea347f25be11a28 *MAMP_MAMP_PRO_5.2.pkg'
Note: the result of this command (for my example file) is either -
shasum: WARNING: 1 computed checksum did NOT match