1、 导入头文件
import <CommonCrypto/CommonDigest.h>
2、加密的方法:
- (NSString *) md5:(NSString *) input {
const char *cStr = [input UTF8String];
unsigned char digest[CC_MD5_DIGEST_LENGTH];
CC_MD5( cStr, strlen(cStr), digest ); // This is the md5 call
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x", digest[i]];
return output;
}
3、调用加密方法:
NSString *str = @"123456";
NSString *result = [self md5:str];
NSLog(@"%@",result);
网友评论