[2017/11/15]解决“Crypto”在Android 7.0 (N) 下无法使用的问题

  • 2017-11-15
  • 0
  • 0

由于在Android N下,谷歌取消了 Crypto Provider ,而AES等算法相关都需要用到这个,在stackoverflow上找到了解决的方案

添加一个类

import java.security.Provider;

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 sr = SecureRandom.getInstance("SHA1PRNG","Crypto");

替换成

SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", new CryptoProvider());

原贴:https://stackoverflow.com/questions/39097099/security-crypto-provider-deprecated-in-android-n/42337802#42337802

评论

还没有任何评论,你来说两句吧