1
votes

When I use md5 encrypt the str, I get the warning:

Implicit conversion loses integer precision: 'unsigned long' to 'CC_LONG' (aka 'unsigned int').

+ (NSString *)md5To32bit:(NSString *)str {

    const char *cStr = [str UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    CC_MD5( cStr, strlen(cStr),digest ); // here I get the warning.
    NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
        [result appendFormat:@"%02x", digest[i]];
    return result;
}
1

1 Answers

2
votes

You can convert the strlen(cStr) to CC_LONG to avoid this warning:

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