Pages

mScrob - Last.fm md5 encoding

My lastFM scrobbler (working title mScrob) is now scrobbling!  The last.fm RESTful API was a bit of learning curve. The documentations is fine if you just following it carefully though.

I'll put the odd bit of code that may be useful. Here's some code to produce the 32 byte md5 encoded data that the API requires:


- (NSString *) md5:(NSString *) toEncode

{

    const char *cStr = [toEncode UTF8String];

    unsigned char digest[32];

    CC_MD5( cStr, strlen(cStr), digest );

    NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];

    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)

        [output appendFormat:@"%02x", digest[i]];

    return  output;

}

No comments:

Post a comment