Skip to content

Instantly share code, notes, and snippets.

@EdGuiness
Created November 22, 2014 10:15
Show Gist options
  • Select an option

  • Save EdGuiness/11559cc8d21d3533b8cf to your computer and use it in GitHub Desktop.

Select an option

Save EdGuiness/11559cc8d21d3533b8cf to your computer and use it in GitHub Desktop.
md5 in C#
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