Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the file integrity check based on md5?

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about the document integrity testing based on md5. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.

Md5sum is a powerful tool for checking file integrity under the Linux platform, and Wikipedia explains md5sum in this way:

Md5sum is a computer program that calculates and verifies 128bit MD5 hashes, where the MD5 hash (or checksum) is used as the digital fingerprint of a file. In theory, like other hash algorithms, a MD5 hash can correspond to an infinite number of files, but from a practical point of view, it is almost impossible for two different files to have the same MD5 hash, unless it is deliberately created. Generally speaking, any non-malicious change to a file will cause its MD5 hash to change, so md5sum is generally used to check the integrity of the file, especially in the case of file transfer, disk error, or other cases where there is no malicious involvement.

Example:

Take shell under linux as an example. The following files are all in the same directory.

Calculate the check value and output it to hash.md5

$md5sum filetohashA.txt filetohashB.txt filetohashC.txt > hash.md5

Obtained documents

The file contains the hash value and the corresponding file name.

$cat hash.md5

595f44fec1e92a71d3e9e77456ba80d1 filetohashA.txt

71f920fa275127a7b60fa4d4d41432a3 filetohashB.txt

43c191bf6d6c3f263a8cd0efd4a058ab filetohashC.txt

Check the file with the MD5 value

$md5sum-c hash.md5

FiletohashA.txt: OK

FiletohashB.txt: OK

FiletohashC.txt: OK

Note: in the check file, there must be two spaces between each md5 check value and the file name to be compared, and the newline in the file should also be UNIX newline character (LF), otherwise it cannot be carried out.

Check a single MD5 value

$echo "595f44fec1e92a71d3e9e77456ba80d1 filetohashA.txt" | md5sum-c

FiletohashA.txt: OK

In practical work, we often need to determine whether there is data loss or data inversion in the copy or network transmission of an important file given by our colleagues. We can complete the data integrity test with the help of MD5 tools. Because the materials provided by our company to customers are downloaded through the network, important files, such as source code, are downloaded. The running binary system for file verification is necessary. After users download the file to the local area, the first thing to do is to verify the accuracy of the file transfer, and can also judge whether the file has been accidentally modified by others.

It is relatively simple to judge a single file, use md5sum A > test.txt to generate a check code, and then md5sum-c test.txt to verify the integrity of the file. In my work, I often check multiple important files, so that we can open the obtained check file and then use:

Echo "595f44fec1e92a71d3e9e77456ba80d1 filetohashA.txt" | md5sum-c

The command method gradually confirms the important files distributed in different folders. Of course, you can also copy the files to be verified into a folder and use:

$md5sum-c hash.md5

The command mode completes the verification at one time.

The following picture is the calibration value of the important file on the TI SDK download page after md5sum. After we download the important file, we download the verification file at the same time to confirm the integrity of the file locally.

The above is the editor for you to share the md5-based file integrity testing is how, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report