How can you generate the same MD5 Hashcode in C# and Java?
Posted
by Sem Dendoncker
on Stack Overflow
See other posts from Stack Overflow
or by Sem Dendoncker
Published on 2010-05-27T09:51:57Z
Indexed on
2010/05/27
10:01 UTC
Read the original article
Hit count: 134
Hi,
I have a function that generates a MD5 hash in C# like this:
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(data);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
sb.Append(result[i].ToString("X2"));
}
return sb.ToString();
In java my function looks like this:
MessageDigest m = MessageDigest.getInstance("MD5");
m.update(bytes,0,bytes.length);
String hashcode = new BigInteger(1,m.digest()).toString(16);
return hashcode;
While the C# code generates: "02945C9171FBFEF0296D22B0607D522D" the java codes generates: "5a700e63fa29a8eae77ebe0443d59239".
Is there a way to generate the same md5 hash for the same bytearray?
Cheers
© Stack Overflow or respective owner