internal static void DecryptStream( BinaryReader reader, Action <BinaryReader> read) { using (BinaryReader decryptedReader = StreamEncryption.DecryptStream(CONTENT_KEY, reader)) { read(decryptedReader); } }
internal static void EncryptStream(BinaryWriter writer, Action <BinaryWriter> save) { // Create a temporary memory stream to hold the unencrypted data using (MemoryStream ms = new MemoryStream()) { // Write to the memory stream BinaryWriter memoryWriter = new BinaryWriter(ms); save(memoryWriter); memoryWriter.Flush(); // Reset to the start of the memory stream, then copy it encrypted ms.Seek(0, SeekOrigin.Begin); StreamEncryption .EncryptStream(CONTENT_KEY, writer, ms); } }