问题
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