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