Monday, June 15, 2009

Validate your downloaded files using md5

When you download files, especially iso for your favourite linux distro, how do you validate the files is properly downloaded or not? This is where md5 checksum comes into picture. From manpage of md5sum; md5sum is used to compute and check MD5 message digest. What is MD5 exactly?

"MD5 is a widely used cryptographic hash function with a 128-bit hash value. As an Internet standard (RFC 1321), MD5 has been employed in a wide variety of security applications, and is also commonly used to check the integrity of files. However, it has been shown that MD5 is not collision resistant; as such, MD5 is not suitable for applications like SSL certificates or digital signatures that rely on this property. An MD5 hash is typically expressed as a 32 digit hexadecimal number "

The above definition is extracted from www.wikipedia.org

To make it simple, the usage to this magnificent tool is just to validate the correctness of any file that we download from the internet. This is very important especially when we downloaded big files such as linux distro iso so that we won't burn a corrupted iso. The easiest way to check the correctness of the iso is by using md5sum

How to use:

to check the md5sum of a file
$ md5sum filename

Example:

Lets say we have a file named test.txt. Run the md5sum command to this file:
$ md5sum test.txt
d968a9cf53f4cb21b06a888e2a6f4cb6

Compare the string that we got with the md5 string provided by the provider of the file. If similar, test.txt is in good order.


If you have more than one file to be checked, use flag -c to check from file. Example, we have 2 files, test.txt and test2.txt, and we want to check both using md5 validation. First, create a file that follow the format where first column is for md5 string, then 2 spaces(press spacebar 2 times) and the next column is the name of the file like below:

d968a9cf53f4cb21b06a888e2a6f4cb6 test.txt
52dba85eb1460f265ddf3de51e91652a test2.txt

Save the file as md5sum.txt

Place the md5sum.txt with test.txt and test2.txt in a same folder

Run md5sum command to check:
$ md5sum -c md5sum.txt

If success, the output will be like this:

test.txt OK
test2.txt OK

You are done with the testing and test.txt and test2.txt is validated as correct using MD5 checksum :)

1 comment:

piju said...

there is winMD5 for m$ windows

http://www.winmd5.com/