Apparently eyes are so blurry I do not see obvious or is this really not obvious?
The keys are the same everywhere. Padding too.
Please help in determining the cause and at least specify the vector direction in which to seek a solution. Thank you.
// BinFormat BinaryFormatter = new BinaryFormatter(); // List tables; // [...] using (Rijndael AES = Rijndael.Create()) { AES.Padding = PaddingMode.PKCS7; PasswordDeriveBytes pdb = new PasswordDeriveBytes(TablesController._baseKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); using (FileStream fStream = File.Open(TablesController._baseFileName, FileMode.OpenOrCreate, FileAccess.Write)) { using (CryptoStream cStream = new CryptoStream( fStream, AES.CreateEncryptor(pdb.GetBytes(32), pdb.GetBytes(16)), CryptoStreamMode.Write)) { binFormat.Serialize(cStream, tables); } } } using (Rijndael AES = Rijndael.Create()) { AES.Padding = PaddingMode.PKCS7; PasswordDeriveBytes pdb = new PasswordDeriveBytes(TablesController._baseKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); using (FileStream fStream = File.OpenRead(TablesController._baseFileName)) { using (CryptoStream cStream = new CryptoStream(fStream, AES.CreateDecryptor(pdb.GetBytes(32), pdb.GetBytes(16)), CryptoStreamMode.Read)) { object deserialized = binFormat.Deserialize(cStream); tables = deserialized as List; } // System.Security.Cryptography.CryptographicException not processed // Message= Padding is invalid and cannot be removed (Filling incorrectly and cannot be removed.) } }