Site icon Bytefreaks.net

Creating an MD5 hash of a string in bash

Advertisements

Make sure that you are not including the new line character (\n) as well in your string, there are cases where it might be included without you explicitly writing it.
For example if you use the output of an echo command in bash, it will automatically add a new line character to the end and will cause your hash to be not the one you would like to have.
For example, the MD5 hash of ‘bytefreaks.net’ (without the quotes) should be 16c00d9cfaef1688d4f2ddfb11b60f46 but if you execute the following you will see you will get a different result.
echo 'bytefreaks.net' | md5sum
01c46835dcb79be359e0b464ae6c6156 -

To avoid this error, use the -n option for echo that will direct the command not to output a trailing new line character.
echo -n 'bytefreaks.net' | md5sum
16c00d9cfaef1688d4f2ddfb11b60f46 -

This post is also available in: Greek

Exit mobile version