为NSString
做一个分类,返回一个MD5过后的字符串
@interface NSString ((gzp_DownLoader))
- (NSString *)md5Str;
@end
@implementation NSString (gzp_DownLoader)
- (NSString *)md5Str {
const char *data = self.UTF8String;
unsigned char digest[CC_MD5_DIGEST_LENGTH];
CC_MD5(data, (CC_LONG)strlen(data), digest);
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;
}