As a hashing algorithm, MD5 is widely used in the encryption process during password transmission. MD As the name implies message Digest (Message digest), you can enter the password, generally a string, encrypted into ciphertext, and this encryption is one-way, unique, theoretically, can not be decrypted, of course, individual websites by collecting simple string input form so-called "Data Dictionary", Then according to everyone's habit, the formation of clear text, this is actually the result of statistical formation, through the comparison to achieve, and the theoretical basis of the MD5 algorithm is not much of a relationship. In recent years, the female Doctor of a university in Shandong is also studying the decryption of the MD5 algorithm, and some algorithms can solve the plaintext of ciphertext, but only the simple string. So, for the time being, the MD5 algorithm is one-way and cannot be decrypted. For details, please refer to the blog: http://www.williamlong.info/archives/1882.html
In general, for clear text transmission, "hackers" have two ways to obtain your password, one is the transmission interception, one is to attack the server, regardless of the clear text can get the password of the specified user. After the MD5 algorithm is encrypted, even if the hacker intercepts the user's password, it cannot be cracked (algorithm unidirectional). In addition, we will struggle with a problem, since the MD5 algorithm can not decrypt, for password encryption, what is the role? User login account is generally through and the server than the account and password to decide whether to have permission to log in, encrypted password encryption of the existence of the server database, the next time the user entered the password to do the cipher-text comparison on the line.
This encounters a problem, in case the user's password is lost, the user will not find the original password? Yes, at this time the general site practice is to use other means of authentication (for example: mobile phone number, etc.), and then password reset. That is why the site will prompt the new password can not be the same as the original password, in fact, this is the result of ciphertext comparison.
It should be explained that the MD5 algorithm, more useful is to form a paper digest to be digitally signed, this is the content of the public key cryptography system, interested can also understand.
The following is the implementation of the MD5 algorithm under the. NET Platform:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Security.Cryptography;5 usingSystem.Text;6 7 namespacemd5encrypted8 {9 class ProgramTen { One Static voidMain (string[] args) A { - //Encryption 123 - //encryption results given on the MD5 website: 202cb962ac59075b964b07152d234b70 the strings = GetMD5 ("123"); -Console.WriteLine ("123MD5 Encrypted Value:"+s); - Console.readkey (); - } + Public Static stringGetMD5 (stringstr) - { + //Create a MD5 object AMD5 MD5 =MD5. Create (); at - //Start Encryption - - //need to convert a string into a byte array - byte[] buffer =Encoding.UTF8.GetBytes (str); - in //returns a well-encrypted byte array - byte[] md5buffer=md5.computehash (buffer); to + /*number of bytes assembled into three formats for strings - parses each element in a byte array into a string according to the specified encoding format the * directly to the array ToString (); 189 123 645---i love you * * Each element in the byte array is ToString (). $ *Panax Notoginseng */ - the + //converts a byte array into a string A //return Encoding.UTF8.GetString (md5buffer); the + stringStrnew =""; - for(inti =0; i < md5buffer.length; i++) $ { $Strnew + = Md5buffer[i]. ToString ("X2");//converts a decimal string into 16 binary - } - returnstrnew; the } - }Wuyi}
There are several areas that need to be explained in relation to the above code:
1, about the conversion of byte array into a string in the implementation of the MD5 algorithm will cause problems.
Because a byte array is converted into a string, as in code, there are generally three forms. However, for the computer is stored in binary, for a string of binary numbers can represent a string of Chinese characters, a string of English characters, and so on, then the byte array of each byte interpretation will be different, so this time to pay attention.
2, Strnew + = Md5buffer[i]. ToString ("X2"); for this sentence, the use of ToString you can check the API. Where the "X" represents 16 binary. The difference between "X" and "X2" is that, for 0x01, "X" is explained by 0x1, while "X2" explains 0x01;
ToString ("X2") is a string format control character in C #
X is hexadecimal
2 is a double digit every time.
such as 0x0A, if not 2, will only output 0xA
Assuming that there are two numbers 10 and 26, the normal hexadecimal display 0xA, 0x1A, so it looks untidy, in order to look good, you can specify "X2", so that the display is: 0x0A, 0x1A.
Reference URL: http://www.cnblogs.com/kuang906/articles/2301361.html
MD5 encryption decryption implements those things on the. NET Platform