参考:http://blog.csdn.net/u011349387/article/details/47318679
1、导入头文件:
#import <CommonCrypto/CommonDigest.h>
2、MD5加密处理
/**
* 对密码进行MD5加密
*/
-(NSString *)passwordMD5HexDigest:(NSString *)password{
if(password == nil){
return nil;
}
const char* str = [password UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(str, (CC_LONG)strlen(str), result);
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH];
for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
[ret appendFormat:@"%02x",result[i]];
}
return key;
}