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