First question: why is this checksum needed? If you do not need cryptographic properties, then a non-crisis hash or a hash that is less cryptographically secure (MD5 is โbrokenโ) does not prevent it from being a good hash, but still strong enough for some uses) it will probably be more effective. You can make your own hash by reading a subset of the data (I would advise making this subset work in 4096 byte files of the main file, as this would correspond to the size of the buffer used by SHA1Managed, as well as allowing you to read a faster chunk than you would if said that every X bytes for some value X).
Edit: A reminder reminding me of this answer also reminded me that I have since written SpookilySharp , which provides high-performance 32-, 64- and 128-bit hashes that are not cryptographic but are good for providing checksums for errors, storage etc. (This, in turn, reminded me that I should update it to support .NET Core).
Of course, if you want the SHA-1 file to interact with something else, you're stuck.
I would experiment with different buffer sizes, as increasing the size of the stream buffer may increase the speed due to additional memory. I would recommend an integer multiple of 4096 (the default is 4096 - the default), since SHA1Managed will request 4096 pieces at a time, and thus there will be no case when the FileStream will be less than the most requested (allowed, but sometimes suboptimal) or at the same time performs several copies.
Jon hanna
source share