SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider(); byte[] data = Encoding.ASCII.GetBytes("hello world"); byte[] hash = sha1.ComputeHash(data); string hashString = BitConverter.ToString(hash).Replace("-", ""); Console.WriteLine(hashString);
using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider()) { using (FileStream fs = new FileStream("filename.txt", FileMode.Open)) { byte[] hash = sha1.ComputeHash(fs); string hashString = BitConverter.ToString(hash).Replace("-", ""); Console.WriteLine(hashString); } }This code creates an instance of the SHA1CryptoServiceProvider class, opens a file named "filename.txt" for reading, computes the SHA-1 hash of the contents of the file, converts the hash to a string of hexadecimal digits, and prints it to the console. The package library for SHA1CryptoServiceProvider is the System.Security.Cryptography package.