On Thu, 2002-09-05 at 20:32, Josh G wrote:
> Anybody here have any idea why MD5 returns 16 bytes in Java????? Should
> I just give up on using MD5 from java full stop?

It sounds to me like it is working!  MD5 is exactly 16 bytes, so if
you're getting 16 bytes, it works.  If you want to turn those 16 bytes
into 32 bytes of hex output, do something like this:

If the md5 is stored in a byte[] called hash:

StringBuffer sb = new StringBuffer(hash.length * 2);
String s;
for(int i = 0; i < hash.length; i++) {
  s = Integer.toHexString(hash[i]);
  if(s.length() == 2) sb.append(s);
  else if(s.length() == 1) sb.append("0" + s);
  else sb.append("00");
}

And then sb will contain the hex-encoded version of the hash.  I'm sure
there are other more efficient ways to do that loop you could try also.

You can verify to yourself that it is working by running that on some
test files, and then comparing the output with the md5sum program that
hopefully came with your system.


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to