我正在使用以下功能在一个Android设备中加密音频数据
private byte[] encrypt(byte[] plaintext) throws Exception
{
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec keySpec = new SecretKeySpec(privateKeyByte, 0, privateKeyByte.length,"AES");
IvParameterSpec ivSpec = new IvParameterSpec(IV);
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
byte[] cipherText = cipher.doFinal(plaintext);
return cipherText;
}
并使用以下
在另一个Android设备上解密 private byte[] decrypt(byte[] cipherText)
{
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec keySpec = new SecretKeySpec(privateKeyByte, 0, privateKeyByte.length, "AES");
IvParameterSpec ivSpec = new IvParameterSpec(IV);
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
return cipher.doFinal(cipherText);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
正在抛出填充块损坏异常。我究竟做错了什么?我非常确定这两个设备的键和IV都相同。