You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Josh G <jo...@gfunk007.com> on 2002/09/06 08:32:58 UTC

MD5 returns 16 bytes???

Anybody here have any idea why MD5 returns 16 bytes in Java????? Should
I just give up on using MD5 from java full stop?




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: MD5 returns 16 bytes???

Posted by Josh G <jo...@gfunk007.com>.
Never mind me, every MD5 I've seen before returned a hex string, i
didn't expect it to return a really big int :)

On Fri, 2002-09-06 at 16: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?
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: MD5 returns 16 bytes???

Posted by Joe Tomcat <to...@mobile.mp>.
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>