Unix (Linux and *BSD) » Security

ID #1003

How to verify the integrity of a file using SHA-512?

You can use SHA for a number of tasks including checking if a file has been altered from its source and its destination. Checking file integrity can be done easily on Unix systems.

1. First, install sha if you don't have it on your system. On PC-BSD and FreeBSD:

$ su -
# pkg_add -r sha

On CentOS and RPM-based systems:

$ su -
# yum install sha

From the manual of sha, you can use several levels of cryptography:

  • -1 Uses SHA-1, which produces a 160-bit hash (40-hex digits);
  • -2 Uses SHA-256, which produces a 256-bit hash (64-hex digits);
  • -3 Uses SHA-384, which produces a 384-bit hash (96-hex digits);
  • -5 Uses SHA-512, which produces a 512-bit hash (128-hex digits).

2. Let's use the strongest encryption. We are going to create a hash of a file called "ports":

$ ls
$ sha -5 ports > myports.sha5
$ ls
ports	myports.sha5

3. Now let's see how we can check integrity of a file. To do so, we need the hash file provided by the author of the file, and the hash file created from the file we have on our computer. We use the cmp tool to compare the two hash files bit by bit:

$ ls
ports	myports.sha5	authorports.sha5
$ cmp myports.sha5 authorports.sha5

If both files are equal, your downloaded file is unchanged, the cmp tool will not return any error message and will return the exit 0 signal to the system. If both hash files are different, cmp will tell you where they are different and will return the exit 1 signal to the system:

$ ls
ports	myports.sha5	authorports.sha5
$ cmp myports.sha5 ports
myports.sha5 ports differ: char 1, line 1
$ cmp myports.sha5 authorports.sha5

This way, you can make sure your file is not corrupted, like you would do using MD5.

Tags: -

Related entries:

Last update: 2008-09-01 06:12
Author: Charles A. Landemaine
Revision: 1.2

Digg it! Print this record Send to a friend Show this as PDF file
Propose a translation for Propose a translation for
Please rate this entry:

Average rating: 4.5 out of 5 (4 Votes )

completely useless 1 2 3 4 5 most valuable

You cannot comment on this entry

Comment of AuinCWQjnENco:
I have been so bewlidered in the past but now it all makes sense!
Added at: 2012-02-15 21:44

Comment of PzIranJhIkchRu:
f3RwqL , [url=http://xmaenjrurwwp.com/]xmaenjrurwwp[/url], [link=http://bfylkixrrqyy.com/]bfylkixrrqyy[/link], http://fizprgkwemvu.com/
Added at: 2012-02-17 09:34

Comment of yiBUFYFOSRqMqDF:
KTGOmE rcfqtmplacss
Added at: 2012-02-21 12:27

Comment of Red Meiziang MSV:
I found products to be a great deal. The Lida lida daidaihua makes me less hungry and the fat burn is helping me overcome my flab. The instructions that came with it told me that getting my eating in balance was necessary for a winning approach. I really took that to heart and have been using a lot more discipline when I am eating and the hoodia makes all that easier. I am doing sit ups and taking products every day and so far, My flab is going away. I dont own a working scale but almost certainly that things are improving podedsja. Red Meiziang MSV
Added at: 2012-11-09 15:48

Comment of H7vPhncAvh:
smutty, June 7, 2012 at 17:03 Not Jolly and not a joker , got to be the worst place to visit whilst in the Dam, he is oxoibonus and extremely rude, he also changes the rules for each and every customer as they come in , we had one drink and left . will never go back again and i suggest no one else wastes there time or money there .
Added at: 2013-11-17 12:55

Comment of KMLhWy83w:
colm keegan, July 3, 2012 at 15:30 It was not my first visit to the Jolly joker but unuartfnotly it was late in my holiday before I got there.I wish I had gotten there sooner because I had forgotten how friendly the people were especially the girl who spells her name with a c instead of s.I give the place 8 out of 10.
Added at: 2013-11-20 00:54

Comment of tZQySo1dNXYB:
cheapest car insurence auto insurance quotes cheap prozac without a prescription here government ato insurance for low income people in north carolina play free online blackjack cheap female car insurance for
Added at: 2014-01-08 11:32

Comment of qDurmFwbH5:
free online auto insurance quotes in Florida sildenafil buy Prdnisone business insurance 21 blackjack online click here
Added at: 2014-01-11 12:26