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.

In the case that you know the length of the data, say between 5 and 8 characters for a password, you can attempt to brute force (try every combination automatically until something hits) the password. For that reason passwords are often salted before being MD5′d however salts and their purpose are outside the scope of this article.

We can use PHP to do the following:

$string = "teststring";
$checksum = md5($string);
echo "The checksum is: " . $checksum . "n";

The output is:


The checksum is: d67c5cbf5b01c9f91932e3b8def5e5f8

We can also 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 “teststringn”. 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

Tags: Linux, md5, md5sum, PHP