C# – Compute SHA256 Checksum
by admin on Mar.15, 2013, under Programming
Example code of how to easily calculate the SHA256 checksum of a file in CSharp:
string checksum = "";
string path = "C:/file.txt";
using (System.IO.FileStream stream = System.IO.File.OpenRead(path))
{
System.Security.Cryptography.SHA256Managed sha = new System.Security.Cryptography.SHA256Managed();
byte[] bytes = sha.ComputeHash(stream);
checksum = BitConverter.ToString(bytes).Replace("-", String.Empty);
}
This class is supported in all regular .NET framework versions according to MSDN.



