我有一个NSData值,我使用以下代码找到该值的字节数
Byte *byteData = (Byte*)malloc(24); //byte array
int len=[result length]; //find the length
memcpy(byteData, [result bytes], len); // copy the bytes values of "result" to bytes array
NSString *MD5Key=[[NSString alloc]initWithFormat:@"%@",[result md5]]; // find md5 values
NSLog(@"%@",MD5Key);
NSString *finalKey=[MD5Key substringToIndex:8];但是我需要字节数组(byteData)的MD5值?我该怎么做呢?
发布于 2013-05-07 22:21:32
我发现了这个方法,希望你能为了你的目标而改变它。
- (NSString *) md5_forString: (NSString*) sourceString
{
const char *cStr = [sourceString UTF8String];
unsigned char result[16];
CC_MD5( cStr, (unsigned int) strlen(cStr), result);
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]
];
}https://stackoverflow.com/questions/16419117
复制相似问题