Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

MD5 hash mismatch of same data in java and c++

843810Oct 23 2002 — edited Oct 24 2002
Hi,

I had already posted this and got not much response....Now i'm posting with code pieces wriiten in java and vc++. The problem is the data which here is 123456 when hashed with java and c++ code gives different results. Why is it so?? At the byte level both should be same right...

a unsigned char of int value 255 is shown out as -1 in java...but bitwise both will have all 8 bits set to one....so what is creating the difference....I have to match the keys at server and client side with the hash.....

An interesting point is any data encrypted by the hash of 123456 in c++ is decrypted in java with no problems.......

But i need to match the hash at both sides and I find it is doesn't match.

java code :

public static void main(String[] args) throws Exception { MessageDigest md= MessageDigest.getInstance("MD5","CryptixCrypto"); md.update(new String("123456").getBytes()); byte[] ndata=md.digest(); System.out.println(new String(ndata)); }

c++ code:

void hasher(char* pin) { BYTE md5[16]; MD5((BYTE *)pin, strlen(pin), md5); printf("%s " , (char *)md5); }void main(){ hasher("123456");}

outPut c++:

_9I�Y�+V_W_��>��e

output java:

�9I�Y��V�W��>

Note : BYTE is unsigned char. And outputs are not properly displayed in the webpage.

Can anyone explain this and tell me how to solve this problem....I've to take the hash load it in a xml doc and send to the server????


Thanx.
Sathish
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 21 2002
Added on Oct 23 2002
2 comments
458 views