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






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

class MainClass
{
    public static void Main(string[] args)
    {
        byte[] key = Encoding.Unicode.GetBytes("yourKey");
        using (KeyedHashAlgorithm hashAlg = KeyedHashAlgorithm.Create("AlgorithmName"))
        {
            hashAlg.Key = key;

            using (Stream file = new FileStream("c:\\text.txt", FileMode.Open,FileAccess.Read))
            {
                byte[] hash = hashAlg.ComputeHash(file);

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








35.12.KeyedHashAlgorithm
35.12.1.Generate the keyed hash code of the file's contents
35.12.2.Secret Key Cryptography: RC2