Generate the hash code of the file's contents : SHA1Managed « Security « C# / CSharp Tutorial






using System;
using System.IO;
using System.Security.Cryptography;

class MainClass
{
    public static void Main(string[] args)
    {
        using (HashAlgorithm hashAlg = new SHA1Managed())
        {
            using (Stream file = new FileStream("C:\\test.txt", FileMode.Open, FileAccess.Read))
            {
                byte[] hash = hashAlg.ComputeHash(file);

                // Display the hash code of the file to the console.
                Console.WriteLine(BitConverter.ToString(hash));
            }
        }
    }
}








35.11.SHA1Managed
35.11.1.Generate the hash code of the file's contents
35.11.2.Generate the hash code of the password
35.11.3.Produce a SHA1 hash