C # Basic _ MD5,

Source: Internet
Author: User

C # Basic _ MD5,

MD5 Encryption

1. Create Md5

2. Start encryption and convert characters into byte arrays.

3. Return an encrypted byte array

4. parse each element in the byte array into a string according to the specified encoding format

1 static void Main (string [] args) 2 {3 4 string s = GetMD5 ("123"); 5 6 Console. writeLine (s); 7 Console. readKey (); 8 9 10} 11 12 13 14 public static string GetMD5 (string str) 15 {16 // create MD5 object 17 MD5 md5 = MD5.Create (); 18 // start encryption 19 // convert the character to a byte array 20 byte [] buffer = Encoding. getEncoding ("GBK "). getBytes (str); 21 // returns an encrypted byte array 22 byte [] MD5Buffer = md5.ComputeHash (buffer ); 23 24 // convert the byte array to a string 25 // byte array --- string 26 // parse each element of the byte array into a string in the specified encoding format 27 // directly convert the Array toString (); 28 // ToString () 29 // return Encoding for each element in the byte array. getEncoding ("GBK "). getString (MD5Buffer); 30 31 // 189 273 345 I love you 32 // 189 273 34533 string strNew = ""; 34 for (int I = 0; I <MD5Buffer. length; I ++) 35 {36 strNew + = MD5Buffer [I]. toString ("x2"); 37} 38 return strNew; 39}

 

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.