"using aes encryption in .net - cryptographicexception saying the padding is invalid and cannot be removed" Code Answer

5

when using a block cipher like aes in a mode that requires padding, like cbc, you must be aware that the output will always be a multiple of the block size. to accomplish this, padding modes like pkcs7 will add some bytes to the cipher at the end of the encryption process. but you have to let the encryptor know when the end occurs. to do so, all you have to do is insert the statement

cryptostream.flushfinalblock();  

after

cryptostream.write(rawdata, 0, rawdata.length);

ps:

perhaps it is just for debugging, but your salt generation method generates the exact same salt every time.

By dgeare on January 2 2022

Answers related to “using aes encryption in .net - cryptographicexception saying the padding is invalid and cannot be removed”

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