需要注意的是,md5加密时,必须导入 #import <CommonCrypto/CommonDigest.h>头文件
+ (NSString *)md5:(NSString *)str{ const char *original_str = [str UTF8String]; unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5(original_str, (unsigned int)strlen(original_str), result); NSMutableString *hash = [NSMutableString string]; for (int i = 0; i < 16; i++) [hash appendFormat:@"%02x", result[i]]; return hash; }