MD5 Encryption Method

Source: Internet
Author: User

First, import two namespaces.

Using System. Security. Cryptography; // md5-encrypted namespace
Using System. Text;

Second, place the following MD5 method in the public class you wrote.

/// <Summary>
/// MD5 Encryption
/// </Summary>
/// <Param name = "strPwd"> encrypted string </param>
/// <Returns> returns the encrypted string </returns>
Public string MD5 (string strPwd)
{
MD5 md5 = new MD5CryptoServiceProvider ();
Byte [] data = Encoding. Default. GetBytes (strPwd); // encode the character into a byte sequence
Byte [] md5Data = md5.ComputeHash (data); // calculate the hash value of the data byte array;
Md5.Clear (); // release all resources used;
String str = "";
For (int I = 0; I <md5Data. Length-1; I ++)
{
Str + = md5Data [I]. ToString ("x"). PadLeft (2, '0 ');
}
Return str;
}

Third, call the md5 method.

Instantiate your common class name. The string to be encrypted in the MD5 method;

The public class name here is DB method name MD5 txtPwd is a textbox Control used to fill in the password

Call Method

DB db = new DB (); // instantiate a public class object;

String passwordmongodb.md5(this.txt Pwd. Text. Trim () // encrypt the password

 

 

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.