安卓安全随机算法



关于 securerandom 的 android 开发者指南 说

Supported Algorithms
SHA1PRNG: Based on SHA-1. **Not guaranteed to be compatible with the SHA1PRNG algorithm on the reference implementation.**
The default algorithm is defined by the first SecureRandomSpi provider<br> found in the VM's installed security providers. Use Security to install custom SecureRandomSpi providers.

当使用相同的值播种时,java 和 android 中的序列是不同的。如何让安卓使用与 Java 中使用的实现相同的sha11prng实现?

一般来说,你需要桌面Java的SecureRandomSpi实现,并将其包含在你的Android项目中。

通过扩展标准的 SecureRandom 实现,您可以使用允许直接指定SecureRandomSpi的受保护构造函数。

但是,使用标准/Oracle Java SHA1PRNG实现并不容易,因为源代码不是SDK的一部分。恕我直言,更简单的方法是从 AOSP 端获取 Android 源代码,提取 Android 上使用的SHA1PRNG实现。这将导致与您要求的相反的方式。

顺便说一句:Android实现是Apache Harmony项目的实现。主要实现在文件org.apache.harmony.security.provider.crypto.SHA1PRNG_SecureRandomImpl中。

最新更新