using System; using System.Security.Cryptography; using System.Text; class MainClass { public static void Main (string[] args) { string data = "Hello World!"; MD5 md5Hash = MD5.Create(); byte[] hash = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(data)); Console.WriteLine(BitConverter.ToString(hash).Replace("-","")); } }
using System; using System.IO; using System.Security.Cryptography; class MainClass { public static void Main (string[] args) { string filePath = @"C:\path\to\file"; SHA256 sha256Hash = SHA256.Create(); byte[] hash; using (FileStream stream = File.OpenRead(filePath)) { hash = sha256Hash.ComputeHash(stream); } Console.WriteLine(BitConverter.ToString(hash).Replace("-","")); } }These examples are part of the .NET Framework Class Library.