我使用下面的代码用md5散列字符串。它工作正常,直到我在64位的iPad Air上测试我的应用程序。然后它与模拟器相比产生了不同的输出。
例如字符串@"1111"
:
这是我的代码:
- (NSString *)MD5String
{
const char *cstr = [self UTF8String];
unsigned char result[16];
CC_MD5(cstr, 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]
];
}
有什么建议吗?
答案 0 :(得分:2)
d41d8cd98f00b204e9800998ecf8427e是空字符串的MD5哈希值。看起来错误在代码中获取字符串,而不是MD5算法。
答案 1 :(得分:-2)
实际上在iPad设备中,它有时会自动生成首字母大写,因此md5加密输出会有所不同。 所以要确保你的情况不会发生。