Created
January 23, 2017 19:51
-
-
Save sachintha81/f91568cf9436214ab341c64be799237f to your computer and use it in GitHub Desktop.
C# - Retrieve MD5 Hash of a File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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