In Android/java app,
byte[] data = ":ʺ$jhk¨ë‹òºÃ"; // fetched from php server..
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, mKeyspec);
return new String(cipher.doFinal(data));
The above code always throws BadPaddingException: pad block corrupted
for following 16 byte encypted data
data = ":ʺ$jhk¨ë‹òºÃ" (the data is 16 chars)
The key is 16 bytes long.
Why does it throw this exception when the data is already the size of a block.? and no padding is needed.
Note: The encrypted data is fetched from a php server.
Edit:
After changing to
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
from
Cipher cipher = Cipher.getInstance("AES");
the decrypt method succeeds, but gives this output