Hash function: an irreversible function. Its input can be a byte stream of any length. Its output is of a fixed size. The hash function is used to generate a digest for your file. It is unique.
For example, y = f (x) x indicates that input y indicates that output x is used to calculate y, which is difficult to calculate x by inputting y.
Our common hash functions MD5 and SHA1 are rare.
DM5: Usually 128 bits 16 bytes
Sha1: generally 160 bits, 8 bits, 20 bytes.
[Root @ redhat ~] # Md5sum/etc/passwd // There are also commands in linux to calculate the md5 value of the file
C79a0c2c792891374595009e6155435c/etc/passwd
[Root @ redhat ~] # Openssl dgst-md5/etc/passwd
MD5 (/etc/passwd) = c79a0c2c792891374595009e6155435c
[Root @ redhat ~] # Openssl dgst-sha1/etc/passwd
SHA1 (/etc/passwd) = b4e99419a91a3908e5e5c9c07a0d91c408c1a008
[Root @ redhat ~] # Sha1sum/etc/passwd
B4e99419a91a3908e5e5c9c07a0d91c408c1a008/etc/passwd
-The hash values provided by the-c parameter to the output are separated:
[Root @ redhat ~] # Openssl dgst-sha1-c/etc/passwd
SHA1 (/etc/passwd) = b4: e9: 94: 19: a9: 1a: 39: 08: e5: e5: c9: c0: 7a: 0d: 91: c4: 08: c1: a0: 08
You can also use md5 to verify the integrity of the file. If a byte of the file changes, the hash value changes over the ground.
Generally, MD5 and sha1 values are released on some official websites to prevent software packages from being tampered.
[Root @ redhat opt] # cat txt
Hello world!
[Root @ redhat opt] # md5sum txt
C897d1410af8f2c74fba11b1db1_e9e txt
[Root @ redhat opt] # cat txt
Holo world!
[Root @ redhat opt] # md5sum txt
Ada39606d10543a059d139d1debb6a37 txt