Log in

No account? Create an account
LiveJournal Client Discussions [entries|archive|friends|userinfo]
LiveJournal Client Discussions

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

MD5 Java Library? [Aug. 4th, 2003|07:21 pm]
LiveJournal Client Discussions


[music |Blueprint - Paradise]

Does anyone know where I can find a library for generating an MD5 hash for use with the livejournal xml-rpc?

[User Picture]From: morallybass
2003-08-04 09:17 pm (UTC)
I'm blocked on the encoding problem kumokasumi alluded to. Given my hash as a byte[], I can either send that (which then gets encoded via base64 tags, internally through the apache xmlrpc library) or I tried just converting the byte[] to a String. When I use the first method, I get "Invalid password", when I use the second I get an RPC fault.

The code is part of a global find/replace tool I'm putting together. It's command line driven at the moment, GUI applet in the works...
(Reply) (Parent) (Thread)
From: karma_chonyi
2003-08-04 09:27 pm (UTC)
I think I found what you need.. it was in the jLiveJournal source.. a new tree I believe. It is a GPL project at www.sf.net/projects/jlivejournal, just so you know.

code =>

private static String getHash(String msg) {
byte buf[] = msg.getBytes();
StringBuffer hexString = new StringBuffer();
try {
MessageDigest algorithm = MessageDigest.getInstance("MD5");
byte[] digest = algorithm.digest();
for (int i = 0; i < digest.length; i++) {
hexString.append(pad(Integer.toHexString(0xFF & digest[i]), 2));
catch (Exception e) {
return hexString.toString();

"msg" in the case, would be, of course, the password.

Formatting is bad, but that is my fault.. looks like it was done w/ a windoze editor or some IDE, so my vim added a bunch of nasty tabs I had to pull out. Sorry
(Reply) (Parent) (Thread)
[User Picture]From: morallybass
2003-08-04 09:30 pm (UTC)
You're my hero. I was 90% there with your previous comment, but that looks like the trick right there. Thanks for the insight on the encoding.
(Reply) (Parent) (Thread)
From: karma_chonyi
2003-08-04 09:33 pm (UTC)
Sorry, there is also a pad() method referred to in that snipped, which I didn't include in my previous post.. here it is =>

private static String pad(String i, int l) {
while (i.length() < l) {
i = '0' + i;
return i;

Formatting sucks again.. I need to get my vim to automatically replace those nasty tabs with spaces like they should have been in the first place.
(Reply) (Parent) (Thread)
[User Picture]From: morallybass
2003-08-04 09:41 pm (UTC)
That did the trick, it's all flying now.

I'll let you know when the GUI is done if you want to play with the tool. The command line version is up on that link I dropped earlier.
(Reply) (Parent) (Thread)
[User Picture]From: alekro
2004-03-09 12:40 pm (UTC)
Thank you for this great code (I mean getHash etc.)!
(Reply) (Parent) (Thread)
[User Picture]From: isapioff
2005-05-06 08:48 am (UTC)
I want to thank you for this piece of code. It's really helpfull for me, I'm goint to use it in my offline client.
(Reply) (Parent) (Thread)