Last Updated: February 25, 2016
· dagams

Evernote/Thrift md5 decoding

The Evernote API provides a bodyHash property on resource types. That property is an NSData object, but converting it to a string using the usual [NSString stringWithData:] or Evernote's custom [data base64EncodedString] did not work. After a long time searching, I found this method to work:

+ (NSString *)evernoteBodyHashToMD5:(NSData*)data
    NSMutableString *sb = [[NSMutableString alloc] init];
    for (long i=0; i<[data length]; i++) {
        UInt8 intVal = 0xff & *((UInt8*)[data bytes]+i);
        [sb appendString: [NSString stringWithFormat:@"%02x", intVal]];
    return [NSString stringWithString:sb];

I put this in a category on NSString for convenience. I found the implementation here