2012-03-11 41 views
1

Android開發者指南說
算法在機器人的安全SecureRandom的隨機

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的順序是不同的。如何讓android使用與java中使用的相同的sha11prng實現?

回答

1

一般而言,您需要實現桌面Java的SecureRandomSpi並將其包含到您的Android項目中。

通過擴展標準SecureRandom實現,您可以使用允許直接指定SecureRandomSpi的受保護構造函數。

然而,使用標準/ Oracle Java SHA1PRNG實現並不像源代碼不是SDK的一部分那麼容易。恕我直言,更簡單的方法是從AOSP結束安卓源碼提取Android上使用的SHA1PRNG實現。這會導致與你所要求的相反的方式。

順便說一句:Android的實現是Apache Harmony項目中的一個。主要實現在文件org.apache.harmony.security.provider.crypto.SHA1PRNG_SecureRandomImpl中。