Skip to content

Instantly share code, notes, and snippets.

@sachintha81
Created January 23, 2017 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sachintha81/f91568cf9436214ab341c64be799237f to your computer and use it in GitHub Desktop.
Save sachintha81/f91568cf9436214ab341c64be799237f to your computer and use it in GitHub Desktop.
C# - Retrieve MD5 Hash of a File
using System;
using System.IO;
using System.Security.Cryptography;
namespace FileHashCompare
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter file path : ");
string filename = Console.ReadLine();
string hash = string.Empty;
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(filename))
{
hash = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToUpper();
}
}
Console.WriteLine(hash);
File.WriteAllText("Output.txt", hash);
Console.Read();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment