BouncyCastleProvider找不到问题解决
Android Studio解决BouncyCastleProvider找不到的问题//AES256加密private byte[] AESEncrypt(String content, byte[] key, byte[] iv){byte[] byteContent = content.getBytes("utf-8");//Security.addProvider(new org.bounc
Android Studio解决BouncyCastleProvider找不到的问题。如下,2021版本的android studio,后面简称AS,在gradle中如果需要使用加密组件,则需要手动在java库里面去添加,然后调用provider去获取。但是在2022版本的AS里,该问题不再存在。如下,注掉的是原来的写法。
//AES256加密
private byte[] AESEncrypt(String content, byte[] key, byte[] iv){
byte[] byteContent = content.getBytes("utf-8");
// Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider())
SecretKeySpec keySpec = new SecretKeySpec(key, "AES")
Cipher cipher1 = Cipher.getInstance("AES/CBC/PKCS5Padding")
cipher1.init(Cipher.ENCRYPT_MODE, keySpec, new IvParameterSpec(iv))
byte[] result = cipher1.doFinal(byteContent)
//print("\n"+Base64.encoder.encodeToString(result)+"\n")
return result
}
更多推荐


所有评论(0)