Md5 encryption and md5 decryption

Source: Internet
Author: User

Md5 encryption and md5 decryption

 

1 public static string GetMD5 (string str) 2 {3 // create an MD5 object 4 MD5 md5 = MD5.Create (); 5 // start to use the MD5 object for encryption 6 byte [] buffer = Encoding. default. getBytes (str); 7 byte [] md5Buffer = md5.ComputeHash (buffer); 8 string strNew = null; 9 // ToString () for each element in the encrypted byte array () 10 for (int I = 0; I <md5Buffer. length; I ++) 11 {12 strNew + = md5Buffer [I]. toString ("x2"); // convert the decimal ---> hexadecimal format 13} 14 return strNew; 15}
X2 in ToString ("x2:
X2 is a formatted string. It is a two-digit hexadecimal number in lowercase.
X indicates hexadecimal, and lowercase x indicates 10 ~ 15. format it to lowercase letters ~ F. uppercase X indicates 10 ~ 15 format to uppercase letters ~ F

2 indicates the output of two digits. The first two digits of the less two digits are filled with 0.
For example
10→0a
9 → 09
175 → af

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.