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


C# Examples » Security » SHA1Managed »

 

Generate the hash code of the file's contents









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




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Security
» SHA1Managed