Generate the keyed hash code of the file's contents : KeyedHashAlgorithm : Security C# Examples


C# Examples » Security » KeyedHashAlgorithm »

 

Generate the keyed hash code of the file's contents









    
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));
                        }
                }
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Security
» KeyedHashAlgorithm