how to calculate md5 and base64 of a string?

Ka-Hing Cheung khc at hxbc.us
Sat Mar 21 11:55:27 EDT 2009


On Sat, 2009-03-21 at 16:34 +0530, Sulabh Mahajan wrote:
> Hello everyone,
> 
> I am coding the yahoo ver 16 login process. When nearly about to
> finish, I realize I don't know how to calculate md5 of a given string
> using libpurple's api. Tried to read the ver 15 login code related to
> finding md5, but thats too complex, intermixed with a lot of stuff not
> needed for the new login.
> 
> I looked at cipher.h, that too passed over my head. I was hoping to
> find some function that would be as easy as say md5(string);
> :P
> Help me here, how do I calculate md5 of a string.

When in doubt, use grep :-)

        unsigned char md5Hash[16];
        cipher = purple_ciphers_find_cipher("md5");
        context = purple_cipher_context_new(cipher, NULL);

        purple_cipher_context_append(context, (guchar *)input,
strlen(input));
        purple_cipher_context_append(context, productKey,
sizeof(productKey) - 1);
        purple_cipher_context_digest(context, sizeof(md5Hash), md5Hash,
NULL);
        purple_cipher_context_destroy(context);

> Also, there is a function in yahoo prpl "to_y64()" that is supposed to
> convert a string to base64, there is a comment regarding it:
> 
> /* This is taken from Sylpheed by Hiroyuki Yamamoto.  We have our own
> tobase64 function
>  * in util.c, but it has a bug I don't feel like finding right now ;)
> */
> 
> What is the history of this thing? Is our base64 function still having
> that bug? Should I use this function to calculate base64 or our own
> function?

I have no idea, but we use it all over so it should be safe.

-khc





More information about the Devel mailing list