MD5
To use the MD5 function we need to use the following command.
md5sum [options] file
Options for the command:
-c
It checks that the generated key by the command match with that file.
-b
I tell the command that the file I'm going to open is binary, in other words, all the ASCII codes from 0 to 255.
-t
I tell the command that the file I'm going to open is text, in other words, only printable characters.
Creating the Hash
In this example, we're going to pass the md5sum manual to a txt file that we're going to name it md5sum.txt, the generated key we're going to pass it to a file called md5sum.md5
man md5sum > md5sum.txt
md5sum -t md5sum.txt > md5sum.md5
Checking the Hash
To check if the previously generated key is correct, we're going to use
md5sum -c md5sum.md5
Calculating the key of multiple files
We're going to pass a folder, in this case /bin
md5sum -b /bin > bin.md5
md5sum -c bin.md5
As we can see, it checks all the files inside the /bin
folder.
Practical cases
The file has been modified
Suppose the file has been modified
nano md5sum.txt
md5sum -c md5sum.md5
As we can see, an error was generated indicating that the key doesn't correspond to the file.
WARNING: 1 computed checksum did NOT match
The key has been modified
We modified the key of the example file.
nano md5sum.md5
md5sum -c md5sum.md5
As we can see, an error was generated indicating that the key doesn't correspond to the file.
WARNING: 1 computed checksum did NOT match
The file doesn't exist
We deleted the example file.
rm md5sum.txt
md5sum -c md5sum.md5
As we can see, an error was generated indicating that the file wasn't found.
WARNING: 1 listen file could not be read
The file is in another place
We moved the file to another place and we checked the key.
mv md5sum.txt md5sum.txt.bak
md5sum -c md5sum.md5
As we can see, an error was generated indicating that the file wasn't found.
WARNING: 1 listen file could not be read
SHA
To use the SHA function we need to use the following command.
shasum [options] files
Options for the command:
-a
Algorithm: 1, 224, 256, 384, 512
-c
It checks that the generated key by the command match with that file.
-b
I tell the command that the file I'm going to open is binary, in other words, all the ASCII codes from 0 to 255.
-t
I tell the command that the file I'm going to open is text, in other words, only printable characters.
Creating the Hash
In this example, we're going to pass the shasum manual to a txt file that we're going to name it shasum.txt, the generated key we're going to pass it to a file called shasum.sha256
man shasum > shasum.txt
shasum -a 256 -b shasum.txt > shasum.sha256
Checking the Hash
To check if the previously generated key is correct, we're going to use
shasum -c shasum.sha256
Calculating the key of multiple files
We're going to pass a folder, in this case /bin
shasum -b /bin > bin.sha256
shasum -c bin.sha256
As we can see, it checks all the files inside the /bin
folder.
Practical cases
The file has been modified
Suppose the file has been modified
nano shasum.txt
shasum -c shasum.sha256
As we can see, an error was generated indicating that the key doesn't correspond to the file.
WARNING: 1 computed checksum did NOT match
The key has been modified
We modified the key of the example file.
nano shasum.sha256
shasum -c shasum.sha256
As we can see, an error was generated indicating that the key doesn't correspond to the file.
WARNING: 1 computed checksum did NOT match
The file doesn't exist
We deleted the example file.
rm shasum.txt
shasum -c shasum.sha256
As we can see, an error was generated indicating that the file wasn't found.
WARNING: 1 listen file could not be read
The file is in another place
We moved the file to another place and we checked the key.
mv shasum.txt shasum.txt.bak
shasum -c shasum.sha256
As we can see, an error was generated indicating that the file wasn't found.
WARNING: 1 listen file could not be read