Click here to Skip to main content
Click here to Skip to main content

MD5SUM FOR C#

By , 5 Jan 2005
 

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:

Code

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 
    MD5CryptoServiceProvider().ComputeHash(FileOrText)).Replace("-","").ToLower();
} 

// 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.

License

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
Member
I am Max Gattringer an Austrian student - I've got a passion for programming C#, cryptograpy and nearly everything concerning PCs Big Grin | :-D

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralThis is great!membermondokat3 Apr '07 - 10:27 
GeneralMD5memberARROLLO2 Jan '06 - 14:12 
HOLA ESPERO ME PUEDAS AYUDAR EN MI PROYECTO Y SI ALGUN COSTO.TRATO DE PROGRAMAR UN MD5 SUM Big Grin | :-D
GeneralPerformancememberaxelriet2 Feb '05 - 16:03 
GeneralYeah, you're right ;-)sussAnonymous7 Jan '05 - 12:36 
GeneralAnother suggestionmemberMrEyes5 Jan '05 - 23:09 
GeneralJust two suggestionsmemberDennis C. Dietrich5 Jan '05 - 10:58 
GeneralRe: Just two suggestionsmemberRobert Rohde5 Jan '05 - 20:09 
GeneralRe: Just two suggestionsmemberDennis C. Dietrich6 Jan '05 - 1:08 
GeneralRe: Just two suggestionsmemberJeffrey Sax6 Jan '05 - 13:52 
GeneralRe: Just two suggestionsmemberMax Gattringer7 Jan '05 - 12:52 

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

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