-
Notifications
You must be signed in to change notification settings - Fork 30
Description
When using this CryptoManager I am getting a BadPaddingException.
I was able to fix it, and I have a theory what might be the cause of this:
In the CryptoManager code you also write the size of the encrypted data. When you read the size information back, you call read(), which will read 1 byte, but an Integer has a size of 4 bytes. So the amount of Bytes read for the encrypted data is wrong, which can result in BadPaddingException. Maybe this works for very small data sizes, since it worked for your sample, I don't have an explanation for it.
My fix was simply to not write the size of the encrypted data to the stream, and when reading the encrypted data part from the stream I am using readBytes() kotlin extension function to just read the rest of the stream.