这种事,弄一个NSString的分类来实现最好
@implementation NSString (MD5)
- (NSString *)MD5String {
const char *cStr = [self UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH] = {0};
CC_MD5(cStr, (CC_LONG)strlen(cStr), result);
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];
for (int i=0; i<CC_MD5_DIGEST_LENGTH; i++) {
[ret appendFormat:@"%02X", result[i]];
}
return ret;
}
@end
使用很简单
NSString *MD5 = [@"123456" MD5String];