【问题标题】:MD5 CC_MD5 works different with iPad 64bit then simulatorMD5 CC_MD5 与 iPad 64bit 和模拟器不同
【发布时间】:2014-03-09 13:31:54
【问题描述】:

我正在使用下面的代码用 md5 散列一个字符串。在我在 64 位 iPad Air 上测试我的应用程序之前,它运行良好。然后它产生了与模拟器不同的输出。

例如字符串@"1111":

  • 在模拟器上 = B59C67BF196A4758191E42F76670CEBA
  • 在 iPad Air 上 = d41d8cd98f00b204e9800998ecf8427e

这是我的代码:

- (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]
            ];
}

有什么建议吗?

【问题讨论】:

  • 顺便说一句。 d41d8cd98f00b204e9800998ecf8427e 不能是您的方法的输出,因为您的方法只创建大写字母。

标签: ios objective-c md5


【解决方案1】:

d41d8cd98f00b204e9800998ecf8427e 是空字符串的 MD5 哈希。看起来错误出在获取字符串的代码中,而不是 MD5 算法。

【讨论】:

    【解决方案2】:

    实际上,在 iPad 设备中,有时它会自动将首字母大写,因此 md5 加密输出会有所不同。 所以请确保它没有发生在您的情况下。

    【讨论】:

      猜你喜欢
      • 2011-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多