Sandeep Sandeep - 25 days ago 5
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 :

VB.net

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


Java

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


Edit: The hash computed using vb.net is
{170,226,106,33,183,52,99,154,17,225,135,139,170,141,116,108}

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 vb.net are different. So i cant go further with DES encryption.

Any help appreciated.

Answer

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.

Comments