In today IT world everything connected and a lot of data is being downloaded from the internet or over networks. This may create some minor problems. The data downloaded may be corrupted or there may be some intruders in network and with the man of the middle attack may change our files. There are different solutions for this but the simplest and fastest solution is using hash algorithms to verify file integrity. There are the different hash function to use but MD5 and SHA1 are popular ones.
在当今的IT世界中,万物互联,并且可以从Internet或网络上下载大量数据。 这可能会产生一些小问题。 下载的数据可能已损坏,或网络中可能有一些入侵者,并且受到中间攻击的人可能会更改我们的文件。 对此有不同的解决方案,但是最简单,最快的解决方案是使用哈希算法来验证文件完整性。 可以使用不同的哈希函数,但是MD5和SHA1是流行的。
下载Nmap(Download Nmap)
We will download nmap
package named nmap-7.31.tgz
from nmap.org
. We will use this file as an example where this file hash is already provided by Nmap web site.
我们将下载nmap
姓包nmap-7.31.tgz
从nmap.org
。 我们将以该文件为例,其中Nmap网站已经提供了该文件哈希。
$ wget https://nmap.org/dist/nmap-7.21.tgz
从网站获取哈希值 (Get Hash Values From Site)
We will calculate hash of downloaded file nmap-7.31.tgz
我们将计算下载文件nmap-7.31.tgz的哈希值
Here are the contents of the hash file about the downloaded Nmap source file with the name of nmap-7.31.tgz.digest.txt
.
以下是有关名为nmap-7.31.tgz.digest.txt
的已下载Nmap源文件的哈希文件的内容。
计算哈希(Calculate Hash)
We will use sha1sum
to calculate SHA1
, md5sum
to calculate MD5
sha24sum
to calculate SHA256
and sha512sum
to calculate SHA512
of the given file.
我们将使用sha1sum
计算SHA1
, md5sum
计算MD5
sha24sum
计算SHA256
和sha512sum
计算给定文件的SHA512
。
$ sha1sum nmap-7.31.tgz
$ md5sum nmap-7.31.tgz
$ sha224sum nmap-7.31.tgz
$ sha512sum nmap-7.31.tgz
As we see newer SHA version creates longer hash because they are more secure and complex. If we check the calculated hash and web site provided hash we can see that everything is OK.
如我们所见,较新的SHA版本会创建更长的哈希,因为它们更安全,更复杂。 如果检查计算出的哈希值和网站提供的哈希值,我们可以看到一切正常。
翻译自: https://www.poftut.com/how-to-check-integrity-of-files-in-linux/