Reputation: 11
I hope that someone could help me with reading exe files in C# and create a SHA1 hash from it. I have tried to read from executable file using StreamReader and BinaryReader. Then using built-in SHA1 algorithm I tried to create a hash but without success. The algorithm results for StreamReader was "AEUj+Ppo5QdHoeboidah3P65N3s=" and for BinaryReader was "rWXzn/CoLLPBWqMCE4qcE3XmUKw=". Can anyone help me to acheive SHA1 hash from exe file? Thx.
BTW Sorry for my English ;)
Upvotes: 1
Views: 2192
Reputation: 4566
StreamReader
implements TextReader
so we are not in a binary world :-)
Upvotes: 0
Reputation: 1502016
Don't use a StreamReader
- that will try to convert the opaque binary data into text data... an exe file is not text data.
Just use a FileStream
and call ComputeHash
:
byte[] hash;
using (Stream stream = File.OpenRead(filename))
{
hash = SHA1.Create().ComputeHash(stream);
}
string base64Hash = Convert.ToBase64String(hash);
Upvotes: 8