Caused by: java.security.NoSuchProviderException: no such provider: Crypto - Android N [duplicate]

我只是一个虾纸丫 提交于 2020-01-11 09:53:28

问题


Seems like "Crypto" provider has been removed in Android N.

My application crashing because of NoSuchProviderException.

If I change the provider and Algorithm then it will affect user who are all using the app currently. Any one have a idea?

KeyGenerator kGen = KeyGenerator.getInstance(KEY_GENERATOR_ALGORITHM);
SecureRandom sr = SecureRandom.getInstance(STR_SHA1PRNG, **CRYPTO**);
sr.setSeed(seed);
kGen.init(128, sr);
SecretKey sKey = kGen.generateKey();

04-30 04:07:02.872: E/AndroidRuntime(17386): Caused by: java.security.NoSuchProviderException: no such provider: Crypto


回答1:


Quoting Google:

The “Crypto” security provider has been removed. Any call to the Java Cryptography Extension (JCE) APIs with a Provider listed should only be done if the provider is included in the code of the APK or be able to deal with it’s absence. The reason applications use this provider is to take advantage of its SecureRandom implementation. If your app was relying on setSeed() to derive keys from strings, you should switch to using SecretKeySpec to load raw key bytes directly OR use a real key derivation function (KDF).

Hence, this is working as intended.

If I change the provider and Algorithm then it will affect user who are all using the app currently.

It appears that you are using that provider only for your random number generation. Hence, switching to a different random number generator, and you follow Google's instructions, this should not affect existing users, if I understand correctly.

And, if I am misunderstanding how you are using Crypto (as I rarely use JCE directly), develop a migration path to upgrade existing users of your app to a different algorithm. Android N should not ship in production form for another couple of months, and even then it will be a slow uptake.



来源:https://stackoverflow.com/questions/36961331/caused-by-java-security-nosuchproviderexception-no-such-provider-crypto-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!