|MD5 Java Library?
||[Aug. 4th, 2003|07:21 pm]
LiveJournal Client Discussions
|||||Blueprint - Paradise||]|
Does anyone know where I can find a library for generating an MD5 hash for use with the livejournal xml-rpc?
Based on the API it says only that the return is a byte. I was curious myself how this would work in the context of passing this through to the server, as it may not be XML-RPC friendly. I do not know if an MD5 hash is, by it's nature, Base64 or not, so as to not cause difficulties.
I plan to play a bit tonight, so perhaps I will find out sooner rather than later.
If you look at the Apache xmlrpc types spec
, it should convert fine within the base64 tag. We shall see if it all connects together properly.
Ah, this I can answer, I think.
The XML-RPC interface wants an XML-RPC string (not a base64 block or an array or anything else) of hexadecimal characters [0-9, a-f].
Here's where I'm hazy about the Java bit. You have to convert the value in the byte array to a hexidecimal string representation. Python offers a hexdigest() method in the md5 module, which is why I posted the nonsense I posted earlier. I don't know what Java offers.
I think you're on the right track. I'm generating my byte hash no problem, but both methods of including it in the rpc call cause problems.
If I send the byte as is (ie: encoded via base64 tag) it claims the password is incorrect.
If I convert the byte to a string directly, it sends back an RPC fault.
You're saying I need to create a String of hexadecimal didgits?
A fairly easy way to turn any byte into it's hex representation, if this is necessary, might be to use Integer.toHexString((int) byteValue); The return value of this call being a string. The entire array could be processed like this, and thrown together in a StringBuffer.
Probably won't get to messing with this tonight. I have the jLiveJournal client code, looked through it briefly, and it seems to use the plaintext password rather than the MD5 hash option.
Very nice solution. Much cleaner than the approach used in jLiveJournal (posted below). Thanks a lot for posting this.