public static string ComputeSha256Hash(string fileName)
{
string sha256Hash = null;
try
{
using (FileStream stream = File.OpenRead(fileName))
{
using (var bufferedStream = new BufferedStream(stream, 1024 * 32))
{
using (var sha = new SHA256Cng())
{
byte[] checksum = sha.ComputeHash(bufferedStream);
sha256Hash = BitConverter.ToString(checksum).Replace("-", string.Empty);
}
}
}
}
catch (IOException) { }
catch (UnauthorizedAccessException) { }
return sha256Hash;
}