I want to store SHA512 checksum of the file for my application. How to do it in common (popular) way? So this checksum can be used but by third party application too.
3 Answers
Write the checksum as lowercase hex digits followed by two spaces and then the filename, with one file per line. This is the format used by md5sum
and the various sha*sum
CLI tools.
$ sha512sum t.txt
d663b43c84ab4ba20040e568d3cb799512fcc00f1053f96f3079345f680b39429adc92f9c8c45fc9ae6053173ddc5b35ade25ae1d5c91e57b809d0c021d5c891 t.txt
$ sha512sum -c <(sha512sum t.txt)
t.txt: OK

- 45,725
TL;DR
The file format is the output of the command you use to generate the digest.
$ shasum -a 512 [FILE] > SHA512SUM # create a checksum file (SHA512SUM)
$ shasum -c SHA512SUM # verify [FILE] from checksum file
[FILE]: OK # output
See these other linux commands for simple ways to generating a checksum file
Long answer
It depends on which implementation of shasum
you are using to check your checksum file.
If you are using a perl implementation ($ shasum -c [FILE]
) then you can find the answer in the man pages. See $ man shasum
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.
If you are using a GNU implementation ($ sha512sum -c [FILE]
) then the answer can be found under their coreutils documentation:
NOTE: The GNU sha digests documentation reference the md5sum digest documentation
For each file, ‘md5sum’ outputs by default, the MD5 checksum, a space, a flag indicating binary or text input mode, and the file name. Binary mode is indicated with ‘*’, text mode with ‘ ’ (space). Binary mode is the default on systems where it’s significant, otherwise text mode is the default. If file contains a backslash or newline, the line is started with a backslash, and each problematic character in the file name is escaped with a backslash, making the output unambiguous even in the presence of arbitrary file names. If file is omitted or specified as ‘-’, standard input is read.
-
Note the bit about the hash being possibly preceded by a forward slash. The newer doco allows for
--zero
which prevents the escaping andNUL
termination. – Tom Hale Sep 17 '19 at 08:06
All schecksum files I've seen were just plain ASCII files which contained the checksum only. This way they may be easily compared with checksum command outputs.
Good practice is to indicate the checksum algorithm used with a filename suffix, eg .md5
or .crc
.

- 2,717
WARNING: 20 lines are improperly formatted
– sdc Sep 16 '16 at 06:30