Get MD5 Hash of any file


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public static string GetMD5Hash(string pathName)
  2. {
  3. string strResult = "";
  4. string strHashData = "";
  5.  
  6. byte[] arrbytHashValue;
  7. System.IO.FileStream oFileStream = null;
  8.  
  9. System.Security.Cryptography.MD5CryptoServiceProvider oMD5Hasher=
  10. new System.Security.Cryptography.MD5CryptoServiceProvider();
  11.  
  12. try
  13. {
  14. oFileStream = GetFileStream(pathName);
  15. arrbytHashValue = oMD5Hasher.ComputeHash(oFileStream);
  16. oFileStream.Close();
  17.  
  18. strHashData = System.BitConverter.ToString(arrbytHashValue);
  19. strHashData = strHashData.Replace("-", "");
  20. strResult = strHashData;
  21. }
  22. catch(System.Exception ex)
  23. {
  24. System.Windows.Forms.MessageBox.Show(ex.Message, "Error!",
  25. System.Windows.Forms.MessageBoxButtons.OK,
  26. System.Windows.Forms.MessageBoxIcon.Error,
  27. System.Windows.Forms.MessageBoxDefaultButton.Button1);
  28. }
  29.  
  30. return(strResult);
  31. }

URL: http://www.codeproject.com/KB/files/dt_file_hasher.aspx

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.