- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"MD5加密";
self.view.backgroundColor = [UIColor lightGrayColor];
NSString *testStr =@"1223";
NSString *md5Str = [self stringChangeMD5:testStr];
NSLog(@"MD5加密结果==== %@",md5Str);
}
- (NSString*)stringChangeMD5:(NSString*)testString {
constchar *str = [testString UTF8String];
unsigned char md[CC_MD5_DIGEST_LENGTH];
CC_MD5(str, (int)strlen(str), md);
NSMutableString * ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH];
for(int i =0; i<CC_MD5_DIGEST_LENGTH;i++) {
/**
X 表示以十六进制形式输入/输出
02 表示不足两位,前面补0输出;出过两位不影响
printf("%02X", 0x123); //打印出:123
printf("%02X", 0x1); //打印出:01
*/
[ret appendFormat:@"%02X",md[i]];
}
return [retcopy];
}