I'm trying to encrypt/decrypt a file with the managed net crypto class: RijndaelManaged
First I didn't set the padding and could write the data then read the data correctly with the correct password
. I then tested with an incorrect password and got the error (exception) message in the title:
padding is invalid and cannot be removed
Some searching later and found that I ought to set the padding mode. I have done that (
RMCrypto.Padding = PaddingMode.PKCS7;
Still same error with an incorrect password.
More searching and found the recommendation to use FlushFinalBlock. Done that just before closing the cryptographic stream. Now on reading I get that error even with the correct password but the data has been decrypted correctly.
What am I doing wrong?