"c#: aes error: padding is invalid and cannot be removed. same key and everything, help" Code Answer

3

based on your edit:

edit: it seems that the size of the encrypted data is 48 bytes (12 bytes more than the original). why is that so? i thought that it only adds bytes if they are not a multiple of the block size (16 bytes, my data is 32 bytes). is data always larger, and with constant increase (i need to know that in order to properly read and decrypt).

if the encrypted data is 48 bytes, thats 16 bytes larger than your original array. this makes sense because the algorithm with pad the data because the default is pkcs7 (even if the size matches the block size, because it pads to the next multiple of the block-size). if you wish to keep it exactly 32 bytes, just change the padding to none

aes.padding = paddingmode.none;
By Mark Rotteveel on May 5 2022

Answers related to “c#: aes error: padding is invalid and cannot be removed. same key and everything, help”

Only authorized users can answer the Search term. Please sign in first, or register a free account.