Can't get rid of exception'the implementation of the rijndael (AES) in C#?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
5 views
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.) } }
by | 5 views

1 Answer

0 like 0 dislike
The code (if you uncomment the declare and initialize tables) is fully operational.
Possible logic fault TablesController'a.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Mar 25, 2019 by Emelyanov
0 like 0 dislike
2 answers
asked May 20, 2019 by reddyk
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
25,705 users