Your code above works as long as the key and iv, used to decrypt the corresponding key and iv, which are used for the encryption. Try the following:
byte[] test = new byte[1000000]; for (int i = 0; i < 256; i++) { test[i] = (byte)i; } var ciphertext = Encrypt(Encoding.Default.GetString(test), "0000000000000000", "0000000000000000"); byte[] check = Decrypt(ciphertext, "0000000000000000", "0000000000000000"); for (int i = 0; i < 256; i++) { Debug.Assert(check[i] == (byte)i, "round trip"); } , " byte[] test = new byte[1000000]; for (int i = 0; i < 256; i++) { test[i] = (byte)i; } var ciphertext = Encrypt(Encoding.Default.GetString(test), "0000000000000000", "0000000000000000"); byte[] check = Decrypt(ciphertext, "0000000000000000", "0000000000000000"); for (int i = 0; i < 256; i++) { Debug.Assert(check[i] == (byte)i, "round trip"); } byte) i, "round trip"); byte[] test = new byte[1000000]; for (int i = 0; i < 256; i++) { test[i] = (byte)i; } var ciphertext = Encrypt(Encoding.Default.GetString(test), "0000000000000000", "0000000000000000"); byte[] check = Decrypt(ciphertext, "0000000000000000", "0000000000000000"); for (int i = 0; i < 256; i++) { Debug.Assert(check[i] == (byte)i, "round trip"); }
As you can see, one million bytes are encrypted and decrypted only with your code, so I don’t think it has anything to do with the size of the data.
However, to change the value IV as follows:
byte[] check = Decrypt(ciphertext, "0000000000000000", "000000000000000X"); // note X
and Debug.Assert will light up - decryption will not match. However, x_cryptostream.Close () succeeds.
Then try changing the key as follows:
byte[] check = Decrypt(ciphertext, "000000000000000X", "0000000000000000"); // note X
Now x_cryptostream.Close () fails CryptographicException, perhaps, "Invalid filling and can not be removed."
key corruption will lead to a decryption failure, and x_cryptostream.Close error () will fail.
I think the problem in the preservation and subsequent reduction of the key bytes.
BTW: We hope you use the full binary range of the key and do not base it only on ASCII characters, otherwise you really do not have a strong key.