Summary:
There is an illegalBlockSizeException issue observed in one particular device type with AES-GCM mode encryption algorithm while encrypting the text(the same issue was not seen earlier with AES-ECB mode but I need to use GCM for my usecase). Based on the further observations, I could see when using AES-GCM mode for encryption, if the input size exceeds 8KB, illegalBlockSize exception is being occurred as mentioned in that particular device type alone whereas other devices handle successfully. As per general norms, AES-GCM should be able to process 2^39^ – 256 bits of plaintext data with the same key when using a 128 bit tag and a 96 bit IV (Detailed Info: here).
But I would like to understand why it’s happening? Are there any reasons behind this behavior? Kindly let me know if anyone has observed similar issue or any inputs regarding the same to understand the fix.
Error log Snippet:
Error preparing data due toIllegalBlockSizeException
javax.crypto.IllegalBlockSizeException
at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:519)
at javax.crypto.Cipher.doFinal(Cipher.java:2055)
Caused by: android.security.KeyStoreException: Unknown error
at android.security.KeyStore.getKeyStoreException(KeyStore.java:858)
at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.update(KeyStoreCryptoOperationChunkedStreamer.java:132)
at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:217)
at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
Language: Java8
OS version: FOS-7 based on Android 9, API Level 28 https://developer.amazon.com/docs/fire-tablets/fire-os-7.html
Usage Info:
- Algorithm Mode => AES/GCM/NoPadding
- IV_BYTES_LENGTH => 12
- GCM_AUTH_TAG_LENGTH => 128
- IV_SPEC => GCMParamterSpec
Other References:
Have found similar issues were reported in Google Issue Tracker(though it doesn’t mention about any size limit as I observed locally) as well but have no resolution.