*de-lurks*

I was just looking at that class... I usually wrap the MessageDigest
stuff in a utility class myself, mainly because it's a few lines of
code that would otherwise get repeated quite a lot.

For hashing a string I usually use this:

public static String getMd5Digest(String input) {
            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                byte[] messageDigest = md.digest(input.getBytes());
                BigInteger number = new BigInteger(1,messageDigest);
                String hash = number.toString(16);
                if (hash.length() == 31) {
                    hash = "0" + hash;
                }

                return hash;
            } catch(NoSuchAlgorithmException e) {
                throw new RuntimeException(e);
            }
        }

I see that our MD5 class also lets you convert to bytes.  It would be
easy enough to extract that from the above snippet - but does anyone
use the byte[] version of an MD5 hash?

I would also question why our MD5 class is synchronising on itself -
as far as I was aware using MessageDigest was a thread-safe operation
- then again, I don't actually know and the API docs don't seem to
mention this one way or the other.

Finally - why bother with the static decode method?   Hashes are
intended to be one way, right?  Even if not, this method seems totally
redundant.

Just some thoughts.

Cheers,
Chris


2009/10/22 Sandro Martini <[email protected]>:
> Hi Todd,
>> Question: what does the MD5 class do that java.security.MessageDigest 
>> doesn't?
> Good question ... I have to look at the code (i made it many months
> ago), and tell you.
>
> Bye
>

Reply via email to