beta.blog

C# – Compute SHA256 Checksum

by 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.


Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!