IOS开发基础之—MD5加密算法【转】
原文地址:http://blog.csdn.net/pjk1129/article/details/6855024
#import <CommonCrypto/CommonDigest.h> @interface NSString (md5) -(NSString *) md5HexDigest; @end #import "NSString+MD5HexDigest.h" @implementation NSString (md5) -(NSString *) md5HexDigest { const char *original_str = [self UTF8String]; unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5(original_str, strlen(original_str), result); NSMutableString *hash = [NSMutableString string]; for (int i = 0; i < 16; i++) [hash appendFormat:@"%02X", result[i]]; return [hash lowercaseString]; } @end