Introduction to MD5:
It is to allow large-capacity information to be "compressed" into a confidential format before signing a private key with digital signature software (that is, to convert a byte string of any length into a large integer of a certain length). Whether it is MD2, MD4, or MD5, they all need to obtain a random length information and generate a 128-bit information digest. Although the structure of these algorithms is more or less similar, the design of MD2 is completely different from MD4 and MD5, because MD2 is designed and optimized for 8-bit machines, while MD4 and MD5 are 32-bit computers. The descriptions of these three algorithms and the C language source code are described in detail in Internet RFCs 1321, the most authoritative document submitted to the IETF in August 1992 by Ronald L. Rivest.
Code:
string JiaMi = Md5Encrypt(LoginPwd); string JieMi = Md5Decrypt(JiaMi); #region MD5 encryption /// <summary> /// MD5 encryption /// </summary> /// <param name="strSource">Strings that require encryption</param> /// <returns> MD5 encrypted string</returns> public static string Md5Encrypt(string strSource) { //Put the string into the byte array byte[] bytIn = (strSource); //Create the key and offset of the encrypted object byte[] iv = { 102, 16, 93, 156, 78, 4, 218, 32 };//Define the offset byte[] key = { 55, 103, 246, 79, 36, 99, 167, 3 };//Define the key //Instance DES encryption class DESCryptoServiceProvider mobjCryptoService = new DESCryptoServiceProvider(); = iv; = key; ICryptoTransform encrypto = (); //Instance MemoryStream Stream Encrypted File ms = new (); CryptoStream cs = new CryptoStream(ms, encrypto, ); (bytIn, 0, ); (); return .ToBase64String(()); } #endregion #region MD5 Decryption /// <summary> /// MD5 decryption /// </summary> /// <param name="Source">Strings that need to be decrypted</param> /// <returns> MD5 decrypted string</returns> public static string Md5Decrypt(string Source) { //Convert decrypted string to byte array byte[] bytIn = .FromBase64String(Source); //Give the decrypted key and offset, the key and offset must be the same as the key and offset during encryption byte[] iv = { 102, 16, 93, 156, 78, 4, 218, 32 };//Define the offset byte[] key = { 55, 103, 246, 79, 36, 99, 167, 3 };//Define the key DESCryptoServiceProvider mobjCryptoService = new DESCryptoServiceProvider(); = iv; = key; //Decrypt the instance stream ms = new (bytIn, 0, ); ICryptoTransform encrypto = (); CryptoStream cs = new CryptoStream(ms, encrypto, ); StreamReader strd = new StreamReader(cs, ); return (); } #endregion
AnotherMD5 encryption method:
MD5 encryption simply means to find the ciphertext through some calculation method. For example: the plain text is: abcdefg through some column operations to obtain the ciphertext 7ac66c0f148de9519b8bd264312c4d64
It has two characteristics: 1. No collision and 2. Irreversible.
No collision means:
7ac66c0f148de9519b8bd264312c4d64 This ciphertext can only be obtained from the plaintext abcdefg. In addition, other plaintexts will never be equal to 7ac66c0f148de9519b8bd264312c4d64, which means that if you don't have those two plaintexts, you will get the same ciphertext after encryption.
Irreversible means:
The plain text is encrypted and the plain text cannot be obtained through the cipher text. In other words, when we know that the plain text adcdefg can obtain 7ac66c0f148de9519b8bd264312c4d64 through encryption, but if we know that a certain text is encrypted, we get 7ac66c0f148de9519b8bd264312c4d64, we cannot calculate who encrypted the text 7ac66c0f148de9519b8bd264312c4d64.
For example, the password set by the user is abcdefg, and when storing, we store the value obtained after encryption of abcdefg is 7ac66c0f148de9519b8bd264312c4d64. Then when the user logs in again, the password abcdefg will be entered. How do we compare whether the two are equal?
We cannot convert the encrypted value to the value before encryption, so our usual approach is to compare the password entered when the user logs in again with the value stored in the database. If it is equal, it means that the password entered is correct.
Need a quoteusing ;
(str, "MD5").ToLower();
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.