Ok, so if there is a bug in MY program, the bug is actually part of the Integer API. Am I wrong?
Please take a look at the Javadoc of Integer.toHexString(int). You will find that it categorically states:
"This value is converted to a string of ASCII digits in hexadecimal (base 16) with no extra leading 0s." So, the Java API sticks to its specification. I wouldn't call this behavior a bug.
So why does java security API allow you to Digest a string but doesn't give you the appropriate methods to return that back to you correctly?
Well, Java API allows Digest of byte arrays. If you want to convert a String to a byte array and then a byte array to a String, it is your problem.
BTW, I should mention that the conversion of String to byte array, and vice-versa, depends on the specific encoding used for conversion. If you do not specify the encoding then the platform-default is used. However, relying on the default encoding is dangerous. Think of this scenario: If you convert string to byte array and calculate digest on your machine in US and send the digest value to an associate in Japan, whose default encoding is different. Now, the digest veirfication will fail even if the original String has not been modified.
[ September 20, 2003: Message edited by: Pankaj Kr ]