在iOS中用MD5加密很多都是转化成16进制,很少有结果用base64编码的.步骤大概是,先转换成data,在转换成base64;
代码
- (NSString *)MD5String {
unsigned char result[CC_MD5_DIGEST_LENGTH];
const char *bytes = [self UTF8String];
CC_MD5(bytes, (CC_LONG)strlen(bytes), result);
NSData *data = [NSData dataWithBytes: result length:16];
NSString *string = [data base64EncodedStringWithOptions:0];//base64编码;
return string;
// return [[NSString stringWithFormat://哈希值
// @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
// result[0], result[1], result[2], result[3], result[4],
// result[5], result[6], result[7], result[8], result[9],
// result[10], result[11], result[12], result[13], result[14], result[15]]lowercaseString];
}