[CryptoAPI] [Request] ComputeHash for files

[CryptoAPI] [Request] ComputeHash for files

Forge Component
Published on 11 Nov by Ricardo Silva
14 votes
Published on 11 Nov by Ricardo Silva
Hi Ricardo.

It would be great if CryptoAPI also had a ComputeHash function for files, instead of only strings.
This would be usefull to create a MD5 checksum for files. 


Hi Carlos,

What kind of files are you expecting to create an hash over? Large files ( over a few MiB ) ?

Hi Ricardo.

Right now I need it for "small" files (up to 2.5/3 MB), but it should work for any file. It just needs another ComputeHash function that has an input parameter of binary data type instead of text.

In .NET would be a simple use of the ComputeHash() method of the MD5 Class (System.Security.Cryptography), which computes a hash for a byte array:


The output should be the same of many tools generating MD5/SHA-256 checksum hashes for files:




I'm not sure hashing a byte array in memory is the solution we want for hashing a several GiB file.

For 2-3 MiB it's fine, but when you reach 100s of MiB it's prolly better to just give the function a file name and read the file 8k bytes at a time to build the hash.

The .NET ComputeHash method also supports an input stream: