[CryptoAPI] [Request] ComputeHash for files

[CryptoAPI] [Request] ComputeHash for files

  
Forge Component
(4)
Published on 2015-11-29 by Ricardo Silva
4 votes
Published on 2015-11-29 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. 

Thanks.

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:

https://msdn.microsoft.com/en-us/library/system.security.cryptography.md5.computehash(v=vs.110).aspx

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

http://www.winmd5.com/

http://getmd5checker.com/

https://www.binaryfortress.com/HashTools/

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:
https://msdn.microsoft.com/en-us/library/xa627k19(v=vs.110).aspx