Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the result of a md5 hash consistant or server dependent?

Tags:

c#

asp.net

hash

md5

I am doing a md5 hash, and just want to make sure the result of:

md5.ComputeHash(bytePassword);

Is consistent regardless of the server?

e.g. windows 2003/2008 and 32/64 bit etc.

like image 726
Blankman Avatar asked Mar 12 '10 21:03

Blankman


2 Answers

MD5 is independent of operating system and architecture. So it is "consistent".

However, MD5 takes as input an arbitrary sequence of bits, and outputs a sequence of 128 bits. In many situations, you want strings. For instance, you want to hash a password, and the password is initially a string. The conversion of that string into a sequence of bits is not part of MD5 itself, and several conventions exist. I do not know precisely about C#, but the Java equivalent String.getBytes() method will use the "platform default charset" which may vary with the operating system installation. Similarly, the output of MD5 is often converted to a string with hexadecimal notation, and it may be uppercase or lowercase or whatever.

So that while MD5 itself is consistent, bugs often lurk in the parts which prepare the data for MD5 and post-process its output. Beware.

like image 133
Thomas Pornin Avatar answered Oct 13 '22 11:10

Thomas Pornin


Yes, it's consistent, the md5 algorithm specification defines it regardless of platform.

like image 18
James Avatar answered Oct 13 '22 10:10

James