Generating MD5 for a string

Introduction


Following Code snippet will help u to generate MD5 hash for a string or text value

Namespaces used


namespace System.Security.Cryptography is required to be included using:

using System.Security.Cryptography;

Classes used


Md5 and MD5CryptoServiceProvider ....to create md5 hash provider

main code



//this is the full code to generate md5
Byte[] generatedBytes,originalBytes;
MD5 md5 = new MD5CryptoServiceProvider();

//convert string data to array of bytes
originalBytes = ASCIIEncoding.Default.GetBytes(txtMD5.Text);

//compute hash on generated byte array
generatedBytes = md5.ComputeHash(originalBytes);

//display hash bytes as readable string as the hash code generated will contain dash(-)
// to remove that Replace function of Regex is used here....
lblGeneratedMD5.Text = Regex.Replace(BitConverter.ToString(generatedBytes), "-", "");


Comments

Author: Shan.R29 Aug 2012 Member Level: Silver   Points : 0

Hi Payal Jain,

How to degenerate your code.

Regards,
Shan.R

Guest Author: Jayesh Sorathia30 Aug 2012

To learn more on Password Encryption in .Net with C# Examples and VB.Net Examples
In this Example we use MD5 algorithm. Means Encrypt password using MD5 algorithm.
Visit this link.
http://jayeshsorathia.blogspot.com/2012/08/net-tips-password-encryption-in-net.html



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: