How to Hash Filestream while writing to file?

248 Views Asked by At

in C# I am using Filestream to write to a new file. I am then hashing this file to get SHA256 hash to verify later. I would like to remove this extra file read, and simply hash file as it is being streamed.

            using (FileStream fs = new FileStream(filePath, FileMode.Create))
            { ...stream file, hash while doing so, give hash upon write finish... }

I have looked at examples of CryptoStream and others, but it is not clear how have a normal filestream that writes to a new file and get a hash while reading. Is this possible, and if so how?

0

There are 0 best solutions below