using System.Security.Cryptography; string input = "Hello World"; SHA256Managed sha256 = new SHA256Managed(); byte[] hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(input));
using System.Security.Cryptography; string filePath = "C:\\example.txt"; SHA256Managed sha256 = new SHA256Managed(); using (FileStream stream = new FileStream(filePath, FileMode.Open)) { byte[] hash = sha256.ComputeHash(stream); }This code creates a SHA256Managed instance, and then uses a FileStream to read the contents of a file and compute its hash value. The hash value is returned as a byte array. Package library: System.Security.Cryptography.