PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Create & Valadate Files With Hash

Go down

Create & Valadate Files With Hash Empty Create & Valadate Files With Hash

Post by jamied_uk 1st May 2018, 17:22

Vid


MD5 Sums are 128-bit character strings (numerals and letters) resulting from running the MD5 algorithm against a specific file. The MD5 algorithm is a popular hash function that generates 128-bit message digest referred to as a hash value, and when you generate one for a particular file, it is precisely unchanged on any machine no matter the number of times it is generated.
It is normally very difficult to find two distinct files that results in same strings. Therefore, you can use md5sum to check digital data integrity by determining that a file or ISO you downloaded is a bit-for-bit copy of the remote file or ISO.
Suggested Read: Progress – Monitor Progress for (cp, mv, dd, tar, etc.) Commands in Linux
In Linux, the md5sum program computes and checks MD5 hash values of a file. It is a constituent of GNU Core Utilities package, therefore comes pre-installed on most, if not all Linux distributions.

Take a look at the contents of
Code:
/etc/group






root❌0:
daemon❌1:
bin❌2:
sys❌3:
adm❌4:syslog,aaronkilik
tty❌5:
disk❌6:
lp❌7:
mail❌8:
news❌9:
uucp❌10:
man❌12:
proxy❌13:
kmem❌15:
dialout❌20:
fax❌21:
voice❌22:
cdrom❌24:aaronkilik
floppy❌25:
tape❌26:
sudo❌27:aaronkilik
audio❌29:pulse
dip❌30:aaronkilik

saved as groups.cvs below.



The md5sums command below will generate a hash value for the file as follows:
$ md5sum groups.csv
bc527343c7ffc103111f3a694b004e2f groups.csv

When you attempt to alter the contents of the file by removing the first line,
Code:
root:x:0:
and then run the command for a second time, try to observe the hash value:
$ md5sum groups.csv
46798b5cfca45c46a84b7419f8b74735 groups.csv

You will notice that the hash value has now changed, indicating that the contents of the file where altered.
Now, put back the first line of the file,
Code:
root:x:0:
and rename it to group_file.txt and run the command below to generate its hash value again:
$ md5sum groups_list.txt
bc527343c7ffc103111f3a694b004e2f groups_list.txt

From the output above, the hash value is still the same even when the file has been renamed, with its original content.
Important: md5 sums only verifies/works with the file content rather than the file name.
The file groups_list.txt is a duplicate of groups.csv, so, try to generate the hash value of the files at the same time as follows.
You will see that they both have equal hash values, this is because they have the exact same content.
$ md5sum groups_list.txt groups.csv
bc527343c7ffc103111f3a694b004e2f groups_list.txt
bc527343c7ffc103111f3a694b004e2f groups.csv

You can redirect the hash value(s) of a file(s) into a text file and store, share them with others. For the two files above, you can issues the command below to redirect generated hash values into a text file for later use:
$ md5sum groups_list.txt groups.csv > myfiles.md5

To check that the files have not been modified since you created the checksum, run the next command. You should be able to view the name of each file along with “OK”.

tecmint.com/generate-verify-check-files-md5-checksum-linux


Last edited by jamied_uk on 1st May 2018, 18:25; edited 4 times in total
jamied_uk
jamied_uk
Admin

Posts : 3020
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Create & Valadate Files With Hash Empty Re: Create & Valadate Files With Hash

Post by jamied_uk 1st May 2018, 17:23

More google.com/search?q=md5+hash+of+file.txt&ie=utf-8&oe=utf-8&client=firefox-b
jamied_uk
jamied_uk
Admin

Posts : 3020
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Create & Valadate Files With Hash Empty Re: Create & Valadate Files With Hash

Post by jamied_uk 2nd May 2018, 00:30

Automatic Script

Code:
#!/bin/bash
# (c) J~Net 2018
#
# jnet.forumotion.com/t1608-create-valadate-files-with-hash
#
# Usage:
#
# ./run.sh file.txt
#
# ./run.sh    (file.txt If you want to answer more questions)!
#
#
# Set Colours
RED='\033[0;31m'
NC='\033[0m' # No Color
#
#
# Clear Up Old Data
#
rm testout1.txt
rm testout2.txt
clear
echo "Welcome To J~Net File Checker"
#
# Check if input empty
var=$1
if [ -z "$1" ]
then
      echo "Enter File Name"
      read var
else
var=$1
      # echo "\$var is NOT empty"
fi
#
# Ended Now doing comparison checks!
if [ -z "$2" ]
then
      echo "Enter File Name To Compare..."
      read var2
else
var2=$2
      # echo "\$var is NOT empty"
fi
#
#
md5sum "$var" > testout1.txt
echo "$var"
cat testout1.txt
md5sum "$var2" > testout2.txt
echo "$var2"
cat testout2.txt
#
if [ $var = $var2 ]
then
      # match="1"
      #echo "Exact Match!"
      echo ""
      text="It Is Authentic!"
      printf "This File Is An ${RED}Exact Match! ${NC}$text\n"
else
      #echo "Do NOT Match!"
      echo ""
      # echo "\$var is NOT empty"
      #match="0"
      text="Authentic!"
      printf "This File Is ${RED}NOT ${NC}$text\n"
fi
#
rm testout1.txt
rm testout2.txt
# clear
#
#
#
# google.com/search?q=infile%3Achecksum.txt
#
# cyberciti.biz/faq/unix-linux-bash-script-check-if-variable-is-empty

Examples:
jamied_uk
jamied_uk
Admin

Posts : 3020
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Create & Valadate Files With Hash Empty Re: Create & Valadate Files With Hash

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum