SyntaxHighlighter

2011/07/22

Verify the integrity of a file before / after download

Sometimes, transfering a file from one place to another can cause damage to the file. And this damage can be subtle enough that it seems fine but the data it contains is just slightly corrupted.

One rather simple way to perform a check is by computing a checksum on this file. An old checksum algorithm is MD5 and a more recent one is SHA1.

Let's suppose you would like to compute a hash key for the file "pet_names.txt" you would like to make available for downloading. The following line shows how to compute its hash key on the host:

user@boing:~$ sha1sum pet_names.txt > pet_sum.txt

Once downloaded, provided you have the file which encloses the sha1 hash key, you can simply check the integrity of the file like this:

user@boing:~$ sha1sum -c pet_sum.txt

Proceeding with MD5 hash key is done in a very similar way; just change sha1sum by md5sum and you're all set!

Hope this may be usefull.

No comments:

Post a Comment