view raw
Sandeep Sandeep - 6 months ago 27
Java Question

Different MD5 hashes for .net and java

`I want to encode my string using .net and pass it to a java program. I am using the same program for encryption and decryption on both the sides. But the java program and .net programs are returning different MD5 hash codes.

Here are the codes for both my programs :

md5Provider = New MD5CryptoServiceProvider()
input = UTF8Encoding.UTF8.GetBytes(sSecurityKey)
oHash = oMd5CryptoServiceProvider.ComputeHash(input)


MessageDigest m;
m = MessageDigest.getInstance("MD5");
byte[] UTF8bytes = key.getBytes("UTF8");

Edit: The hash computed using is

The m.digest() i get in java is
{-44, 29, -116, -39, -113, 0, -78, 4, -23, -128, 9, -104, -20, -8, 66, 126}

The problem is that m.digest() from java and oHash from are different. So i cant go further with DES encryption.

Any help appreciated.


At last I found the answer. I just converted the Md5 hash into BigInteger and then converted into an byte array. Now when i pass it as a key to the DES algorithm, i get my desired output.