Why does my md5sum hash not match other md5s?

Posted on

Problem :

So for a school assignment we are working with hashes. However I’ve encountered a problem where my file.txt containing:

test hashes
test hashes

without quotes doesn’t match the hash from HashCalc (for windows) and http://www.md5hashgenerator.com/ both come up with cd7e8e88f33efb42e0a1148e92c5005b while md5sum on my kali linux comes up with f3c5fdf4320346eb9bd2a6b64235248e using

head -c -1 file.txt | md5sum

It works fine with just one line of test hashes, but with the second line I can’t make it match.

Solution :

$ echo -ne "test hashesntest hashes" | md5sum                                   
f3c5fdf4320346eb9bd2a6b64235248e  -
$ echo -ne "test hashesrntest hashes" | md5sum                                 
cd7e8e88f33efb42e0a1148e92c5005b  -

It’s about Unix (n) vs. DOS line ending (rn).

You can convert Unix line endings to DOS ones with unix2dos:

$ echo -ne "test hashesntest hashes" | unix2dos | md5sum
cd7e8e88f33efb42e0a1148e92c5005b  -

The reverse command is dos2unix.

Leave a Reply

Your email address will not be published. Required fields are marked *