C # MD5 Encryption
Using System. Security. Cryptography;
Using System. Text;
Namespace MD5
{
///
/// MD5 Encryption Algorithm
///
Public class MD5Encryptor
{
# Region 9 Public Methods
///
/// MD5 Encryption
///
/// String to be encrypted
/// Encrypted string
Public string Encrypt (string text)
{
// 1. Create an MD5 object
MD5 md5 = new MD5CryptoServiceProvider ();
// 2. encode the character into a byte sequence
Byte [] data = System. Text. Encoding. Default. GetBytes (text );
// 3. Calculate 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 and initialize the character memory
StringBuilder str = new StringBuilder ();
Str. Append (string. Empty );
// 6. Store encrypted characters
For (int I = 0; I <md5data. Length-1; I ++)
{
Str. Append (md5data [I]. ToString ("x"). PadLeft (2, '0 '));
}
// 7. Return the MD5-encrypted string
Return str. ToString ();
}
# Endregion
}
}