How do I make this go faster? It currently takes about 30 seconds on a 3gb file. I am using this to get a checksum from the file to compare it to Microsoft's official checksums. I am wondering if using a buffer would help and if so how should I do that?
public static String GetSHA1Hash(string fileName)
{
string strResult = String.Empty;
string strHashData = String.Empty;
byte[] arrbytHashValue;
System.IO.FileStream oFileStream = null;
System.Security.Cryptography.SHA1CryptoServiceProvider oSHAHasher =
new System.Security.Cryptography.SHA1CryptoServiceProvider();
try
{
oFileStream = GetFileStream(fileName);
arrbytHashValue = oSHAHasher.ComputeHash(oFileStream);
oFileStream.Close();
strHashData = BitConverter.ToString(arrbytHashValue);
strHashData = strHashData.Replace("-", String.Empty);
strResult = strHashData;
}
catch (Exception ex) { return ex.Message; }
finally { ((IDisposable)oSHAHasher).Dispose(); }
return (strResult);
}
GetFileStream
look like? \$\endgroup\$gb
in the question, you meanGB
(gigabyte)? Lowercaseb
should be used for bits and lower caseg
isn't standard. \$\endgroup\$