Currently I am implementing into my C++/CLI code a function that return the SHA1 value of a file. It is a Windows Forms application in Visual Studio.
I chose to implement the .NetFramework class SHA1CryptoServiceProvider because it is really fast (believe me). I have tested several algorithms but none of them were as fast as the SHA1CryptoServiceProvider class.
The problem is that in my application there is a progressBar showing the progress of computing SHA1 and the SHA1CryptoServiceProvider class doesn’t have any function that returns progress of computing SHA1.
Here is the code:
using namespace System::Security::Cryptography;
using namespace System::IO;
StreamReader^ Reader = gcnew StreamReader("C:\\abc.exe");
SHA1CryptoServiceProvider^ SHA1 = gcnew SHA1CryptoServiceProvider();
String^ Hash = "";
Hash = BitConverter::ToString(SHA1->ComputeHash(Reader->BaseStream));
return Hash;
Finally I have done it. I post the code, maybe someone will find it useful. I know the code is not clean, I am still learning. It can compute SHA1 of files larger that 2^31 bytes. Tested it on a 22GB file. Works fine in backgroundWorker 🙂