开发者

Different MD5 hashes for .net and java

开发者 https://www.devze.com 2023-04-07 19:19 出处:网络
`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

`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 oH开发者_如何学JAVAash from vb.net are different. So i cant go further with DES encryption.

Any help appreciated.


You may want to compare input from both digest methods byte by byte. That is input from VB.net and UTF8bytes from Java. Most likely they will be different (could be some encoding specifics of VB.net, for example). Also, how do you compare results?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号