The differences of several kinds of MD5 encryption on the Internet

Source: Internet
Author: User

(1)

Using System.Security.Cryptography;

byte[] result = Encoding.Default.GetBytes (YPS);//tbpass a text box for entering a passwordMD5 MD5 =NewMD5CryptoServiceProvider (); byte[] Output =Md5.computehash (Result); stringstr = bitconverter.tostring (output). Replace ("-",""); if(str. length!= +) System.Diagnostics.Debug.WriteLine ("Start Debugging"); returnStr

(2)

Using System.Security.Cryptography;

            stringCL =Yps; stringPWD =""; MD5 MD5= MD5. Create ();//instantiate a MD5 pair of images//after the encryption is an array of byte type, here should pay attention to the choice of coding utf8/unicode, etc.            byte[] s =Md5.computehash (Encoding.UTF8.GetBytes (CL)); if(S.length! = -) System.Diagnostics.Debug.WriteLine ("Start Debugging"); //converts an array of byte types to a string by using a loop, which is a regular character formatting the resulting             for(inti =0; i < s.length; i++)            {                //The resulting string is formatted using the hexadecimal type. The formatted character is a lowercase letter, and if uppercase (X) is used, the character after the format is uppercase charactersPWD = pwd + s[i]. ToString ("X"); }            if(pwd. Length! = +) System.Diagnostics.Debug.WriteLine ("Start Debugging"); returnPwd

(3)

Using System.Web.Security;

" MD5 ");

The above three ways of MD5 encryption, the specific principle is not a cicada. Talk about the tiny difference.

(1) The MD5 value is the same as (3). (2) The MD5 value of (1) and (3) is slightly different because

PWD = pwd + s[i]. ToString ("X"), when the statement is converted to 16 binary, if the conversion value is one, such as 3, the other two methods at this time the value of the conversion is 03, resulting
The last Md5 value is less than or equal to 32 bits, resulting in Md5 values (2) and (1), (3) not necessarily equal
Therefore, if MD5 is encrypted, it is best to use the same method.

The differences of several kinds of MD5 encryption on the Internet

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.