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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

md5sum equivalent in java

843810Jul 26 2002 — edited Jul 27 2002
Hi,
md5sum on solaris produces "9b9af6945c95f1aa302a61acf75c9bd6" for the string "abcde".
But when I tried using the following sample code,
MessagDigest md = MessageDigest.getInstance("MD5");
String str = "abcde";
byte[] bytes = md.digest(str.getBytes());

StringBuffer hexString = new StringBuffer();
for (int i=0;i<bytes.length;i++) {
hexString.append(Integer.toHexString(0xFF & bytes));
}
System.out.println(hexString.toString());

This prints "ab56b4d92b40713acc5af89985d4b786".
Why Java implementation of MD5 is different from md5sum of solaris. How can I achieve the same result.

Thanks,
Sreedhar.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 24 2002
Added on Jul 26 2002
9 comments
261 views