Creating an MD5 on Linux

An MD5 is a type of Hash, also, a Checksum.

An MD5 hash is a one way verification sum which can be used to verify a string or contents of a file. Once you have a file and an MD5 checksum, the recipient of the file can also perform an MD5 calculation to ensure that the file’s contents are unchanged. They may have been changed maliciously such as in the case of a binary file, or simply by data corruption. An MD5 is NOT a type of encryption. It can not be reversed.
We can use PHP to do the following:

< ?php $string = “teststring”; $checksum = md5($string); echo “The checksum is: ” . $checksum . “\n”; ?>

The output is:

The checksum is: d67c5cbf5b01c9f91932e3b8def5e5f8

We can use the ‘md5sum’ linux command and pipe input to it via STDIN.

echo “teststring”|md5sum

test:~# echo “teststring”|md5sum
50be80a7a199c13e2bb09e2e745ba233 –

Why is the output of this md5sum different to that above? Well, ‘echo’ automatically adds a newline to the string to make it “teststring\n”. We can surpress this with -n:

test:~# echo -n “teststring”|md5sum
d67c5cbf5b01c9f91932e3b8def5e5f8 –

We can also run the md5sum command against a file:

test:~# md5sum /bin/bash
c8770eb0a3f2b6088914b4bc29301113 /bin/bash

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.