我在我的安卓应用程序中使用了这个库https://github.com/wg/scrypt。我可以在我的安卓应用程序中成功编译并绑定本机实现,但如果在32位或64位环境下执行scryptN函数会产生不同的结果,这怎么可能呢?相反,java实现在这两种环境中都能很好地工作。
要重现这个问题,只需使用NDK构建共享库并尝试运行此函数
public String hashPassword(String plainPassword) {
final int shift = 14;
final int n = 1 << shift;
final int r = 8;
final int p = 1;
final int dklen = 64;
try {
return ByteUtils.toHexString(SCrypt.scrypt(
plainPassword.getBytes("utf-8"),
"theseed".getBytes("utf-8"),
n, r, p, dklen));
} catch (Exception e) {
LogHelper.e("error hashing password", e);
return null;
}
}如果您在32位架构或64位架构上运行,您将获得不同的输出
谢谢
发布于 2017-07-18 15:01:42
最后我找到了一个解决方案:
对于任何在Android上使用这个库的人,我建议使用这个分支
https://github.com/lhunath/scrypt
它有一个完整的android ndk项目设置,您只需从src/android/jni文件夹运行ndk-build (当然,您需要正确配置NDK ),它将生成一组.so文件。
注意:您必须更改Application.mk文件,以便为所有平台生成它们
https://stackoverflow.com/questions/45144962
复制相似问题