Created
November 22, 2014 10:15
-
-
Save EdGuiness/11559cc8d21d3533b8cf to your computer and use it in GitHub Desktop.
md5 in C#
This file contains hidden or 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; | |
| class test { | |
| static void Main(string[] args) { | |
| string file = ""; | |
| if (args.Length > 0) { | |
| file = args[0]; | |
| FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); | |
| BinaryReader r = new BinaryReader(fs); | |
| byte[] d = new byte[fs.Length]; | |
| d = r.ReadBytes((int)fs.Length); | |
| byte[] result = MD5hash(d); | |
| string s = ""; | |
| foreach (byte b in result) { | |
| s += b.ToString("x2"); | |
| } | |
| Console.WriteLine(s.ToUpper()); | |
| } | |
| } | |
| static byte[] MD5hash (byte[] data) { | |
| MD5 md5 = new MD5CryptoServiceProvider(); | |
| byte[] result = md5.ComputeHash(data); | |
| return result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment