I also encountered this problem in the actual process.
Google explanation of this issue
If you specify the provider by name or by instance—for example, Cipher.getInstance("AES/CBC/PKCS7PADDING", "BC") or Cipher.getInstance("AES/CBC/PKCS7PADDING", Security.getProvider("BC"))—the behavior you get in Android P will depend on what API level your application targets. For apps targeting an API level before P, the call will return the BC implementation and log a warning in the application log. For apps targeting Android P or later, the call will throw NoSuchAlgorithmException.
To resolve this, you should stop specifying a provider and use the default implementation.
before
public static byte[] getAESKey(){
String seed = UUID.randomUUID().toString();
try{
KeyGenerator kgen = KeyGenerator.getInstance("AES");
String SHA1PRNG = "SHA1PRNG";
SecureRandom sr;
CryptoProvider provider = new CryptoProvider();
sr = SecureRandom.getInstance(SHA1PRNG, provider);
sr.setSeed(seed.getBytes());
int keyLength = 128;
kgen.init(keyLength,sr);
SecretKey sKey = kgen.generateKey();
byte[] aesKey = sKey.getEncoded();
return aesKey;
}catch(Exception e){
e.printStackTrace();
}
return null;
}
after
public static byte[] getAESKey(){
String seed = UUID.randomUUID().toString();
try{
KeyGenerator kGen = KeyGenerator.getInstance("AES");
SecureRandom sr;
sr = new SecureRandom();
sr.setSeed(seed.getBytes());
int keyLength = 128;
kGen.init(keyLength,sr);
SecretKey sKey = kGen.generateKey();
return sKey.getEncoded();
}catch(Exception e){
e.printStackTrace();
}
return null;
}
and it's work for me