Last active
June 6, 2016 20:22
-
-
Save pilotgeraldb/db3626db98c49cd8e43bce863690fff1 to your computer and use it in GitHub Desktop.
creates a hash of a file from a filename
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 (MD5 md5 = MD5.Create()) | |
{ | |
using (FileStream stream = File.OpenRead(filename)) | |
{ | |
byte[] bytes = md5.ComputeHash(stream); | |
bool uppercase = false; | |
StringBuilder result = new StringBuilder(bytes.Length * 2); | |
for (int i = 0; i < bytes.Length; i++) | |
{ | |
result.Append(bytes[i].ToString(uppercase ? "X2" : "x2")); | |
} | |
return result.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment