You can use the static method from the constructor to generate a crypto stream similar to the following:
public class EncryptingFileStream : System.IO.StreamReader { public EncryptingFileStream(string fileName, byte[] key, byte[] IV) : base(GenerateCryptoStream(fileName, key, IV)) { } private static System.IO.Stream GenerateCryptoStream(string fileName, byte[] key, byte[] IV) { using (System.Security.Cryptography.Rijndael rijAlg = System.Security.Cryptography.Rijndael.Create()) { rijAlg.Key = key; rijAlg.IV = IV;
To use this class:
using (EncryptingFileStream fs = new EncryptingFileStream("test.crypt", DX_KEY_32, DX_IV_16)) { string line; // Read and display lines from the file until the end of // the file is reached. while ((line = fs.ReadLine()) != null) { Console.WriteLine(line); } }
source share