Click here to Skip to main content
13,768,132 members
Click here to Skip to main content
Add your own
alternative version


16 bookmarked
Posted 23 Feb 2008
Licenced CPOL

Calculating MD5 Checksum

, 25 Feb 2008
Rate this:
Please Sign up or sign in to vote.
A C# program showing how to use the System.Security.Cryptography.MD5 class.


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 );
   } // End of using fileStream
} // End of CalculateChecksum 

Points of Interest

You can see both the full code for this article as well as download the executable from here.


  • 1.0: Submitted this article.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

CEO Compilr
Canada Canada
Kyle Hankinson is the Owner and Operator of the Online Compiler website Compilr ( He enjoys programming both as a hobby and a job.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
Ankur\m/5-Oct-11 0:27
professionalAnkur\m/5-Oct-11 0:27 
GeneralVery helpful and simple! Pin
Thomas ST16-Apr-09 3:22
memberThomas ST16-Apr-09 3:22 
GeneralHi Ser! Pin
Mehmet CINCI23-Feb-08 3:27
groupMehmet CINCI23-Feb-08 3:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.181116.1 | Last Updated 25 Feb 2008
Article Copyright 2008 by zenox
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid