There is another parameter in which you can specify whether to allow another process to read or write to the file
openFile is the file name, line type.
using (FileStream fileIn = new FileStream(openFile, FileMode.Open, FileAccess.Read, FileShare.Write)) using (FileStream fileOut = new FileStream(openFile, FileMode.Open, FileAccess.Write, FileShare.Open))
This way you can read and write to the same file.
while (myfileStream.Position < fileLength) { fileIn .Read(buffer, 0, 51200); buffer = encrypt(buffer); fileOut .Write(buffer, 0, 51200); }
Although itโs easy and you donโt need to write to a temporary file or move / rename it, etc., it can be really dangerous if for some reason the encryption suddenly breaks, you will lose data! A
In addition, the encryption function is what I implemented. AesCryptoServiceProvider together with CryptoStream can be used :)
source share