classProgram {Static voidMain (string[] args) { //MD5 encryption is irreversible strings = GetMD5 ("123"); Console.WriteLine (s); Console.readkey (); } Public Static stringGetMD5 (stringstr) { //Create a MD5 objectMD5 MD5 =MD5. Create (); //Start Encryption//need to convert a string into a byte array byte[] buffer =Encoding.Default.GetBytes (str); //returns a well-encrypted byte array byte[] Md5buffer =md5.computehash (buffer); //converts a byte array into a string//byte array to string, theoretically there are 3 ways//parses each element in a byte array into a string Encoding.Default.GetString (Md5buffer) According to the specified encoding format; //directly set the array to ToString (); Pass//each element in the byte array is ToString (); //return Encoding.Default.GetString (md5buffer); stringSTR1 =NULL; for(inti =0; i < md5buffer.length; i++) {str1+ = Md5buffer[i]. ToString ("X2"); } returnstr1; } }
. NET Learning notes----2015-06-30 (MD5 encryption)