首先,导入头文件
#import <CommonCrypto/CommonDigest.h>
#pragma mark MD5算法
- (NSString *)md5HexDigest:(NSString *)url
{
const char *original_str = [urlUTF8String];
unsignedchar result[CC_MD5_DIGEST_LENGTH];
CC_MD5(original_str, strlen(original_str), result);
NSMutableString *hash = [NSMutableStringstring];
for (int i =0; i <16; i++)
[hash appendFormat:@"%02X", result[i]];
return [hashlowercaseString];
}