MD5 Introduction:
is to allow bulk information to be "compressed" into a confidential format before signing a private key with a digital signature software (that is, converting an arbitrary-length byte string into a long, large integer). Whether it's MD2, MD4, or MD5, they all need to get a random length of information and generate a 128-bit message digest. Although these algorithms are more or less similar in structure, the design of MD2 is completely different from MD4 and MD5 because MD2 is designed for 8-bit machines, while MD4 and MD5 are for 32-bit computers. The description of these three algorithms and the C language source code are described in detail in Internet RFCs 1321, which is the most authoritative document submitted to the IETF by Ronald L. Rivest in August 1992.
Code:
stringJiami =Md5encrypt (LOGINPWD); stringJiemi =Md5decrypt (Jiami); #regionMD5 encryption/// <summary> ///MD5 Encryption/// </summary> /// <param name= "strsource" >strings that need to be encrypted</param> /// <returns>MD5 the encrypted string</returns> Public Static stringMd5encrypt (stringstrsource) { //Put the string in a byte array byte[] Bytin =System.Text.Encoding.Default.GetBytes (strsource); //establish keys and offsets for encrypted objects byte[] IV = {102, -, the,156, +,4,218, +};//defining offsets byte[] key = { -,103,246, -, $, About,167,3};//Defining Keys//Instance des encryption classDESCryptoServiceProvider Mobjcryptoservice =NewDESCryptoServiceProvider (); Mobjcryptoservice.key=IV; Mobjcryptoservice.iv=key; ICryptoTransform Encrypto=Mobjcryptoservice.createencryptor (); //instance MemoryStream stream encryption fileSystem.IO.MemoryStream ms =NewSystem.IO.MemoryStream (); CryptoStream CS=NewCryptoStream (MS, Encrypto, CryptoStreamMode.Write); Cs. Write (Bytin,0, bytin.length); Cs. FlushFinalBlock (); returnSystem.Convert.ToBase64String (Ms. ToArray ()); } #endregion #regionMD5 decryption/// <summary> ///MD5 Decryption/// </summary> /// <param name= "Source" >the string to decrypt</param> /// <returns>MD5 decrypted String</returns> Public Static stringMd5decrypt (stringSource) { //converts a decrypted string into a byte array byte[] Bytin =System.Convert.FromBase64String (Source); //given the decrypted key and offset, the key and offset must be the same as the key and offset at the time of encryption byte[] IV = {102, -, the,156, +,4,218, +};//defining offsets byte[] key = { -,103,246, -, $, About,167,3};//Defining KeysDESCryptoServiceProvider Mobjcryptoservice =NewDESCryptoServiceProvider (); Mobjcryptoservice.key=IV; Mobjcryptoservice.iv=key; //The instance stream is decryptedSystem.IO.MemoryStream ms =NewSystem.IO.MemoryStream (Bytin,0, bytin.length); ICryptoTransform Encrypto=Mobjcryptoservice.createdecryptor (); CryptoStream CS=NewCryptoStream (MS, Encrypto, CryptoStreamMode.Read); StreamReader STRD=NewStreamReader (CS, Encoding.default); returnSTRD. ReadToEnd (); } #endregion
. NET MD5 Cryptographic Decryption Code