Home
Manage Your Code
Snippet: Get md5 of file (C#)
Title: Get md5 of file Language: C#
Description: Calculates the md5 hash of a file. Views: 736
Author: Henrik Bie Date Added: 1/30/2008
Copy Code  
1System.IO.FileStream fs = new FileStream(@"C:\temp\test.xml", FileMode.Open, FileAccess.Read);
2            
3System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
4byte[] bytes = md5.ComputeHash(fs);
5
6StringBuilder sBuilder = new StringBuilder();
7                        
8for (int i = 0; i < bytes.Length; i++)
9{
10       sBuilder.Append(bytes[i].ToString("x2"));
11}