Calculate hash when writing to stream
问题 I am currently creating an encrypted file format that needs to be signed. For this I need to calculate the hash code of the content I have written to a stream. In the .net framework there is numerous hash algorithms that can be used, and it works fine, but it requires me to process the stream three times. byte[] content = new byte[] { 0, 1, 2, 3, 4, 5, 6 }; using (Stream fileStream = File.Open("myfile.bin", FileMode.Create)) { //Write content fileStream.Write(content, 0, content.Length); }