Issue
i am encrypting audio data in one android device using following function
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;
}
and decrypting on another android device using following
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;
}
it is throwing pad block corrupt exception. What am I doing wrong? I am very sure that both of devices are having the same key and IV.
Solution
I changed pkc5Padding to NoPadding and it worked. not sure not having padding would make it insecure. But it worked.
Answered By - Devarsh Mavani
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.