Hi all,
I've copyed this code from someone else and trying to get it to work...
public static String getKeyedDigest(String input, String key) {
:
:
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(input.getBytes());
digest = md.digest(key.getBytes());
dstr = new BigInteger(1, digest).toString(16);
/* this is important, toString leaves out initial 0 */
if (dstr.length() % 2 > 0)
dstr = "0" + dstr;
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
Unfortunately it retuns the correct check ... but not the leading
zero's which I need.
What it returned: 96f07821d958764gcc1fcd76d12358
expected: 0096f07821d958764gcc1fcd76d12358
or
What it returned: 0454abc257b09547a8a7f87c785328
expected: 000454abc257b09547a8a7f87c785328
TIA
shakah - 29 Jun 2005 13:01 GMT
> Hi all,
>
[quoted text clipped - 26 lines]
>
> TIA
Two quick hacks:
dstr = new BigInteger(1, digest).toString(16);
while(dstr.length() < 32) {
dstr = "0" + dstr ;
}
-- or --
dstr = (new BigInteger("100000000000000000000000000000000").add(
new BigInteger(1,
digest).toString(16)).toString(16)).substring(2) ;
Roedy Green - 30 Jun 2005 07:26 GMT
>Unfortunately it retuns the correct check ... but not the leading
>zero's which I need.
add 10000000000000000000000000000 and trim it off later, or count the
missing 0s in the final result and prepend some.
See Misc.rep in the http://mindprod.com/products.html#BUSINESS

Signature
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes