C#C
C#3y ago
34 replies
Surihia

❔ Increase Hash computing speed.

So I am trying to make a simple app for my use case that computes SHA256 of two files. right now I have this following code which works but is extremely slow:
        static void Main(string[] args)
        {
            var inFile_1 = args[0];
            var inFile_2 = args[1];

            Console.WriteLine("Computing hash....");
            using (FileStream fs = new FileStream(inFile_1, FileMode.Open, FileAccess.Read))
            {
                using (SHA256 mySHA256 = SHA256.Create())
                {
                    fs.Position = 0;
                    byte[] HashBuffer = new byte[4096];

                    HashBuffer = mySHA256.ComputeHash(fs);

                    Console.WriteLine(BitConverter.ToString(HashBuffer).Replace("-", ""));
                    Console.ReadLine();
                }
            }
        }

I have only set it to get the hash for one file. my issue is the speed of the hash computing is extremely slow. is there any way by which I can increase the speed ?
Was this page helpful?