1 @interface NSString (MD5) 2 3 + (NSString *)md5To32bit:(NSString *)str; 4 5 @end 6 7 8 @implementation NSString (MD5) 9 10 + (NSString *)md5To32bit:(NSString *)str { 11 12 const char *cStr = [str UTF8String]; 13 unsigned char digest[CC_MD5_DIGEST_LENGTH]; 14 CC_MD5( cStr, (CC_LONG)strlen(cStr),digest ); 15 NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; 16 for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) 17 [result appendFormat:@"%02x", digest[i]]; 18 return result; 19 } 20 21 @end
时间: 2024-10-05 18:51:06