Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

Today, we will talk about encryption, and talk about the popularization of knowledge related to MD5.

The principle of the MD5 algorithm is described as follows: THE MD5 code processes the input information in 512-bit groups, and each group is divided into 16 32-bit groups. After a series of processing, the output of the algorithm consists of four 32-bit groups. After cascading the four 32-bit groups, a 128-bit hash value is generated.

The MAIN features of MD5 are as follows: It is irreversible. The MD5 values of the same data must be the same, but the MD5 values of different data are different

It is indeed theoretically possible for an MD5 to correspond to an infinite number of texts, because MD5 is finite and texts can be infinite. For example, the mainstream use of MD5 maps arbitrarily long “bytes” to a 128bit large integer. So there are 2^128 possibilities, which is about 3.4 * 10^38, which is a finite number, but there are an infinite number of possibilities in the world that can be used to encrypt texts

Since MD5 is irreversible, there is no decryption. So where is MD5 widely used?

For password management

When we need to save some password information for identification, if the password information is directly stored in the database in plain code, without any security measures, the system administrator can easily get the original password information, once these information is leaked, the password is also easy to be deciphered. To increase security, it is necessary to encrypt the information in the database that needs to be kept secret, so that even if someone gets hold of the entire database, the original password information cannot be retrieved without a decryption algorithm. MD5 algorithm can solve this problem well.

When we log in, we need to compare whether the MD5 value of the password entered by the customer is the same as that of the database. If the MD5 value is the same, the login is successful; otherwise, the login fails. Therefore, under normal circumstances, we go on some websites or software password, no matter what level of the company, are not available. To us, the MD5 value is just a string of random garbled characters. So when we lose the password, we have to reset the password. We will encrypt the saved password with MD5 again, overwriting the original saved password, and the saved password in the database becomes another MD5 value.

The above summary is the back-end server commonly used MD5 encryption, to give you popular science about the database is how to save. In the actual application, there are many direct use of MD5 module, we directly use the line.

The import hashlib m = hashlib md5 () m.u pdate (b '123') m.h exdigest () # 202 cb962ac59075b964b07152d234b70 encrypted resultCopy the code

This is a simple example in Python.

You are welcome to discuss procedural questions with me and answer any questions you may have. Follow the public number: poetic code, make a friend.