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.