为什么80%的码农都做不了架构师?>>>
用到SHA1PRNG算法从加密提供者那里取得的密钥,发现在Android 7.0以上会报错
java.security.NoSuchProviderException: no such provider: Crypto
同时给出一个官网链接:
https://android-developers.googleblog.com/2016/06/security-crypto-provider-deprecated-in.html
参考:
http://stackoverflow.com/questions/36813098/securerandom-provider-crypto-unavailable-in-android-n-for-deterministially-gen
http://stackoverflow.com/questions/39097099/security-crypto-provider-deprecated-in-android-n/42337802#42337802
发现7.0以上安卓已经放弃这种方式,对于7.0以上可以实现一个提供者
public class CryptoProvider extends Provider {
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");
}
}
调用:
SecureRandom.getInstance("SHA1PRNG", new CryptoProvider());