Calculate md5 Hash in C#

December 11, 2012 // In: C#

Its common practice to store passwords in database using some hashing algorithms instead of plain text. The main purpose of hashing is to secure password from theft. If anyone some how  gets the access to the database and extracts the passwords, hashing algorithm will give him a tought time to decrypt and know its actual password.

For example:

4f5416e6ba80dee7c0839c020546ca86 is a hashing form of sharp-coders

MD5 is a common hashing algorithm to convert string to hash to secure your passwords. Its 32 character string of hexadecimal numbers. Hashing usually falls in the category of Cryptography.

Lets Start!

What you have to do is to include Cryptography namespace in your project.

Here is the implementation of the function that converts string to md5 hash. It accepts one parameter and in that parameter you pass your string that you want to convert into hash.

I’ve also commented the code inside the function for your understanding. You can call this function to convert your string to md5 hash.

Example:

I’ve developed  a Console Based project, and here is the complete code

If you face any difficulty or want to say something about this article, feel free to ask in the comments.

Load Data into GridView in ASP.Net
Format Numbers to Fix Length in C#