Android 7.0 AES加密报错:NoSuchProviderException: no such provider: Crypto

最近项目中遇到手机密码不能登录的问题,在别的地方看到了的解决方法,这里记录一下

报错代码:
Android 7.0 AES加密报错:NoSuchProviderException: no such provider: Crypto_第1张图片
调用SecureRandom.getInstance就会抛出异常:NoSuchProviderException: no such provider: Crypto,原来CryptoProvider在7.0以上不存在了

解决代码:
Android 7.0 AES加密报错:NoSuchProviderException: no such provider: Crypto_第2张图片
还要在项目中手动添加一个CryptoProvider类:

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");
    }
}

你可能感兴趣的:(Android-适配,Android异常问题)