C#MD5 encryption

Source: Internet
Author: User
Tags md5 encryption

Using System.Security.Cryptography;
Using System.Text;

Namespace MD5
{
<summary>
MD5 Encryption algorithm
</summary>
public class Md5encryptor
{
#region 9 Public Methods

<summary>
MD5 encryption
</summary>
<param name= "text" > strings that need to be encrypted </param>
<returns> string after encryption </returns>
public string Encrypt (string text)
{
1. Create a MD5 object
MD5 MD5 = new MD5CryptoServiceProvider ();
2. Encode characters into a sequence of bytes
byte[] data = System.Text.Encoding.Default.GetBytes (Text);
3. Computes the hash value of the data byte array
byte[] Md5data = md5.computehash (data);
4. Release all resources in the MD5 object
MD5. Clear ();
5. Create character memory and initialize
StringBuilder str = new StringBuilder ();
Str. Append (String. Empty);
6. Storing encrypted characters
for (int i = 0; i < Md5data. Length-1; i++)
{
Str. Append (Md5data[i]. ToString ("X"). PadLeft (2, ' 0 '));
}
7. Return the string after MD5 encryption
Return str. ToString ();
}

#endregion
}
}

C#MD5 encryption

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.