I am thinking on creating a program on C# to get the SHA1 binary base64 hash of a series of very large files.
Right now I can accomplish that by running this instruction on OpenSSL:
openssl sha1 -binary FILENAME | openssl base64
however I haven´t found references for the "binary" and "base64" parts to obtain the same result with C#.
Is it possible? Maybe call openssl inside C#?
Thank you.
You need to use the Convert.ToBase64String method and the System.IO namespace to read binary:
string GetBase64EncodedSHA1Hash(string filename)
{
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
using (SHA1Managed sha1 = new SHA1Managed())
{
return Convert.ToBase64String(sha1.ComputeHash(fs));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With