This is ideal and desirable, technical, if your writing method does not change the file length and always stands behind the reader, this should not create any problems. In fact, from an API point of view, this is desirable as it allows the user to control where to read and where to write. (This is the recommended specification for writing to another file, in case of any bad events during the encryption process, your input file will not be corrupted).
Sort of:
protected void Encrypt(Stream input, Stream output) { byte[] buffer = new byte[2048]; while (true) {
Now that you are using encryption, I would even recommend doing the actual encryption in another specialized thread. This clears the code well.
class MySpecialHashingStream : Stream { ... } protected void Encrypt(Stream input, Stream output) { Stream encryptedOutput = new MySpecialHashingStream(output); input.CopyTo(encryptedOutput); }
source share