Hashing is a project that I personally like and use often. However it hasn't been updated in a while. This fork is mainly intended for personal use though hopefully it will also be useful for somebody else. My main idea was to update it to target .NET 9 though I had fun trying to improve it in other ways.
- As mentioned the project now requires NET 9, which offers runtime support for SHA-3 without relying on third-party code
- Other hashing algorithms now use the classes in the
System.Security.Cryptographynamespace, abandoning obsolete classes such asMD5CryptoServiceProvider - Most of these hashing algorithms run now in parallel for each input file, at the cost of higher memory usage. Well worth the trade-off in most cases.
- Added progress reporting in the UI which is quite nice for large files
- Added a unit test project to ensure correctness
- Added a benchmark project can be used to evaluate the performance of the different approaches
- .No built-in support for RIPEMD160 in .NET 9 so this algorithm can't be run in parallel with the others. See https://github.com/sshnet/Cryptography for source code.
- Cancelling hashing operations is still unrealiable
For a random file of 50 MB:
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|---|---|---|---|---|---|
| BenchAllOriginalAlgorithms | 1,707.2 ms | 197.41 ms | 10.82 ms | - | 11.62 KB |
| BenchAllDotNet9 | 1,506.6 ms | 164.31 ms | 9.01 ms | - | 7.42 KB |
| BenchAllDotNet9OpenOnceChunks_655360ChunkSize_Parallel | 599.6 ms | 101.52 ms | 5.56 ms | - | 940.34 KB |
Hashing times are close to one third of the original, at the expense of higher memory usage.
For a random file of 500MB:
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
|---|---|---|---|---|---|---|
| BenchAllOriginalAlgorithms | 17.117 s | 0.6608 s | 0.0362 s | - | - | 11.62 KB |
| BenchAllDotNet9 | 15.087 s | 0.3486 s | 0.0191 s | - | - | 7.7 KB |
| BenchAllDotNet9OpenOnceChunks_655360ChunkSize_Parallel | 6.158 s | 0.1904 s | 0.0104 s | 1000.0000 | - | 3510.99 KB |
So times seem to scale linearly with the size of the file. Fortunately that's not the case for allocated memory. Still, it'd be interesting to perform a deep analysis on memory consumption and see if there's something that can be done about it.