Click here to Skip to main content
11,935,053 members (53,983 online)
Click here to Skip to main content
Add your own
alternative version


14 bookmarked


, 5 Jan 2005
Rate this:
Please Sign up or sign in to vote.
How to compute the same hash as MD5SUM does (HEX).

Reason For This Howto

As you may know the MD5CryptoService, which the .NET Framework uses, doesn't create an md5 sum's string. So you only have the pure byte[] which isn't that useful if you want to use it in a database or on your Web Server to compare the sum with your file's sum! So, if many people have no idea how to get their sum into the right way, here's my howto to create the same sums like "md5sum" does:


This is the second version with the Hex-bug fixed.

using System.Security.Cryptography;
string MD5SUM(byte[] FileOrText) //Output: String<-> Input: Byte[] //
return BitConverter.ToString(new 

// Quite simple isn't it? I hope you enjoyed this tiny article and 
//I hope I could help ya! //

You can use this example of course for SHA1 as well, just change the MD5CryptoServiceProvider to SHA1CryptoServiceProvider.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Max Gattringer
Austria Austria
I am Max Gattringer an Austrian student - I've got a passion for programming C#, cryptograpy and nearly everything concerning PCs Big Grin | :-D

You may also be interested in...

Comments and Discussions

GeneralThis is great! Pin
mondokat3-Apr-07 11:27
membermondokat3-Apr-07 11:27 
GeneralMD5 Pin
ARROLLO2-Jan-06 15:12
memberARROLLO2-Jan-06 15:12 
GeneralPerformance Pin
axelriet2-Feb-05 17:03
memberaxelriet2-Feb-05 17:03 
I just timed the three versions (BitConverter, string += and StringBuilder) and interestingly, the BitConverter version was the quickest! I got 1.7331s, 1.8552 and 1.8447, respectively, for 100K iterations, timed with QueryPerformanceCounter. I used a 1 byte input array to minimize the checksum computation part. Without the call to ToLower(), the BitConverter version took 1.6099s.

I think the reason to prefer StringBuilder over += is more linked to the fact that += creates temporary strings and causes the GC to work harder. In this test the raw speed difference was marginal.

GeneralYeah, you're right ;-) Pin
Anonymous7-Jan-05 13:36
sussAnonymous7-Jan-05 13:36 
GeneralAnother suggestion Pin
MrEyes6-Jan-05 0:09
memberMrEyes6-Jan-05 0:09 
GeneralJust two suggestions Pin
Dennis C. Dietrich5-Jan-05 11:58
memberDennis C. Dietrich5-Jan-05 11:58 
GeneralRe: Just two suggestions Pin
Robert Rohde5-Jan-05 21:09
memberRobert Rohde5-Jan-05 21:09 
GeneralRe: Just two suggestions Pin
Dennis C. Dietrich6-Jan-05 2:08
memberDennis C. Dietrich6-Jan-05 2:08 
GeneralRe: Just two suggestions Pin
Jeffrey Sax6-Jan-05 14:52
memberJeffrey Sax6-Jan-05 14:52 
GeneralRe: Just two suggestions Pin
Max Gattringer7-Jan-05 13:52
memberMax Gattringer7-Jan-05 13:52 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 5 Jan 2005
Article Copyright 2005 by Max Gattringer
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid