Skip to Main Content

Java Programming

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 as an integer

807589Nov 29 2008 — edited Nov 29 2008
folks how can i calculate md5 as integer.. we get it as Hex String. or byte[].. but how as string.. and when i talk about integer, i mean "int" i-e a small enough value to be accomodated easily in int.. here is my code
    MessageDigest md = null;
    try {
      md = MessageDigest.getInstance("MD5");
    }
    catch(Exception  e) { 
      e.printStackTrace();
    }
    byte [] md5Sum = new byte[32];
    md.update(buffer,start,end);
    md5Sum = md.digest();
    for(int i = 0;i < md5Sum.length; i++) {
    	System.out.println(md5Sum);
}
return Math.abs(byteArrayToInt(md5Sum, 0)); // still is problamatic.. how to convert byte[] to int is my question

i have tried BigInt.intvalue() but it also works only for some cases ??                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 27 2008
Added on Nov 29 2008
7 comments
2,620 views