Introduction
I was looking for a simple way to calculate the MD5 checksum of multiple files on my computer for security reasons. Although I found programs that could do one file at a time, it would be tedious to go through all of my files. So, I wrote a simple utility that recursively checks directories and files, and outputs their MD5 checksum.
Using the code
First, you need to declare an instance of the MD5
class which can be found in the System.Security.Cryptography
namespace.
private static MD5 md5 = MD5.Create ( );
The main function of the program is the "CalculateChecksum
" function, as seen here:
private static string CalculateChecksum ( string file )
{
using ( FileStream stream = File.OpenRead ( file ) )
{
byte [] checksum = md5.ComputeHash ( stream );
return ( BitConverter.ToString ( checksum ).Replace ( "-", string.Empty );
}
}
Points of Interest
You can see both the full code for this article as well as download the executable from here.
History
- 1.0: Submitted this article.