What is the MD5 algorithm
MD5 Message-Digest Algorithm (English: MD5 Message-Digest Algorithm), a widely used cryptographic hash function that can produce a 128-bit The hash value (hash value) of 16 bytes is used to ensure that the information transmission is complete and consistent.
MD5 function(Recommended learning: web front-end video tutorial)
Input information of any length, and after processing, the output is 128-bit information (digital fingerprint);
Different inputs result in different results (uniqueness);
MD5 does not belong to the encryption algorithm
People who think it does not belong to it are because they feel that they cannot get the original text from the ciphertext (hash value), that is, there is no decryption algorithm, so these people think that MD5 It can only belong to an algorithm and cannot be called an encryption algorithm;
Those who think it belongs are because they feel that they cannot see the original text after MD5 processing, that is, the original text has been encrypted, so they think MD5 is an encryption algorithm; I personally support it The former is just like thinking that the BASE64 algorithm can only be regarded as encoding.
Is the MD5 algorithm reversible?
The reason why MD5 is irreversible is that it is a hash function and uses a hash algorithm. During the calculation process, part of the original information is lost.
However, it is worth pointing out that in theory, one MD5 may indeed correspond to countless original texts, because there are a limited number of MD5s and there can be countless original texts. For example, the mainstream MD5 maps a "byte string" of any length into a 128-bit large integer.
That is, there are a total of 2^128 possibilities, which is about 3.4*10^38. This number is finite. , but there are countless possibilities for the original text that can be used to encrypt in the world.
But one thing to note is that although this is a theoretical finite versus infinite, the problem is this Infinity is not completely true in real life, because on the one hand, the length of the original text is often limited in reality (taking commonly used passwords as an example, most people are within 20 digits), on the other hand, we currently want to find that two pieces of original text correspond to the same It is very difficult to create an MD5 value (technically called hash collision). Therefore, in a sense, it is entirely possible to construct a one-to-one correspondence between the MD5 value and the original text within a certain range. Therefore, MD5 is currently the most effective The attack method is rainbow table. You can learn the details through Google.
MD5 is equivalent to lossy compression.
MD5 uses
1. Prevent tampering:
1) For example, when sending an electronic document, before sending, I first get the MD5 output result a. Then after the other party receives the electronic document, the other party also gets an MD5 Output result b. If a is the same as b, it means it has not been tampered with in the process.
2) For example, if I provide file downloads, in order to prevent criminals from adding Trojans to the installation program, I can publish the installation files on the website. The obtained MD5 output result.
3) SVN also uses MD5 when detecting whether the file has been modified after CheckOut.
2. To prevent direct viewing of plain text:
Many websites now store the MD5 value of the user's password when storing the user's password in the database. In this way, even if the criminals obtain the MD5 value of the user's password in the database, they will not be able to know the user's password. (For example, in a UNIX system, the user's password It is encrypted with MD5 (or other similar algorithms) and stored in the file system.
When the user logs in, the system calculates the password entered by the user into an MD5 value, and then saves it in the file system Compare the MD5 value in the system to determine whether the entered password is correct.
Through such steps, the system can determine the legitimacy of the user's login to the system without knowing the clear code of the user's password. This is not only It can prevent the user's password from being known by users with system administrator rights, and also increases the difficulty of password cracking to a certain extent.)
3. Prevent repudiation (digital signature):
This requires a third-party certification agency. For example, A writes a document, and the certification agency uses the MD5 algorithm to generate summary information for the file and keep a record.
If A later says that the document was not written by him, the authority The organization only needs to regenerate the summary information for the document, and then compare it with the summary information recorded in the record. If they are the same, it will be proved that it was written by A. This is called a "digital signature".
MD5 security
It is generally believed that MD5 is very safe, because the brute force cracking time is unacceptable to ordinary people. In fact, it is very unsafe if the user's password is MD5 processed and then stored in the database.
Because the user's password is relatively short, and many users' passwords use birthdays, mobile phone numbers, ID numbers, phone numbers, etc. Or use some commonly used auspicious numbers or an English word. If I MD5 the commonly used passwords first, store the data, and then match it with your MD5 result, then I may get the plaintext.
For example, there is an MD5 cracking website http://www.cmd5.com/default.aspx, so the password policy of most websites now is to force users to use a combination of numbers and uppercase letters to improve the security of user passwords. .
The above is the detailed content of md5 encryption algorithm. For more information, please follow other related articles on the PHP Chinese website!