Security “Crypto” provider deprecated in Android N
一个用户在android n中运行我的应用程序,他崩溃了。我知道google不赞成android n中的加密提供商,但是什么是迁移旧的加密数据的最好方法。
8.0及以上版本可在此处参考
对于低于8.0的版本,您可以通过以下代码。
您可以使用此提供程序替换SecureRandom的"crypto",它对我很好:
使用,
1 | SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", new CryptoProvider()); |
而不是,
1 | SecureRandom sr = SecureRandom.getInstance("SHA1PRNG","Crypto"); |
号
以及下面的CryptoProvider类,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import java.security.Provider; /** * Implementation of Provider for SecureRandom. The implementation supports the *"SHA1PRNG" algorithm described in JavaTM Cryptography Architecture, API * Specification & Reference */ public final class CryptoProvider extends Provider { /** * Creates a Provider and puts parameters */ public CryptoProvider() { super("Crypto", 1.0,"HARMONY (SHA1 digest; SecureRandom; SHA1withDSA signature)"); put("SecureRandom.SHA1PRNG", "org.apache.harmony.security.provider.crypto.SHA1PRNG_SecureRandomImpl"); put("SecureRandom.SHA1PRNG ImplementedIn","Software"); } } |