Calculate the Hash Code of a File - CSharp Security

CSharp examples for Security:Hash

Description

Calculate the Hash Code of a File

Demo Code


using System;// w ww.  ja  va2  s.c o m
using System.IO;
using System.Security.Cryptography;

class MainClass
    {
        public static void Main(string[] args)
        {
            using (HashAlgorithm hashAlg = HashAlgorithm.Create(args[0]))
            {
                using (Stream file = new FileStream(args[1], FileMode.Open, FileAccess.Read))
                {
                    byte[] hash = hashAlg.ComputeHash(file);

                    Console.WriteLine(BitConverter.ToString(hash));
                }

            }
        }
    }

Result


Related Tutorials