Everybody nowadays thinks in terms of securing data. For securing data cryptography comes into the picture. Cryptography is nothing but writing down your plain text into secure code format.
Basically in Linux there are two methods of cryptography.
- Encryption: This method uses plain text as a input & transforms it into some other form using the coding technique “cipher” & this can only be decrypted using a key. Here the key plays major role in converting the plain text into decrypted form “cipher text” & vice versa.
Hence this process is a two way from and to, to and from
- Hashing: This method also takes plain text as input however it applies hash to represent binary form of the plain text input. we cannot convert the output into plain text as in case of encryption. Hence its one way process.
Basically this method helps us to find out the changes done to file once file is “hashed”. I will explain this in demo section.
so Lets move to practical way of doing it..
1. Encryption
Steps:
- Create a file uxtechno.txt with a line in it : I Love UxTechno!!!!
[root@kalwa2 encypt_demo]# cat uxtechno.txt I Love UxTechno!!!!
- Now let’s Encrypt with 3DES and salt which introduces randomness and reducess vulnerabilities to brute force attacks.This command will ask for password twice.
[root@kalwa2 encypt_demo]# openssl des3 -salt -in uxtechno.txt -out uxtechno_test.des3 enter des-ede3-cbc encryption password: Verifying - enter des-ede3-cbc encryption password: [root@kalwa2 encypt_demo]# ls -ltr total 8 -rw-r--r--. 1 root root 20 Jun 21 06:19 uxtechno.txt -rw-r--r--. 1 root root 40 Jun 21 06:19 uxtechno_test.des3
- Now let’s decrypt the cipher(use the same password used in step 2):
[root@kalwa2 encypt_demo]# openssl des3 -d -salt -in uxtechno_test.des3 -out dec_test.txt enter des-ede3-cbc decryption password: [root@kalwa2 encypt_demo]# ls -ltr total 12 -rw-r--r--. 1 root root 20 Jun 21 06:19 uxtechno.txt -rw-r--r--. 1 root root 40 Jun 21 06:19 uxtechno_test.des3 -rw-r--r--. 1 root root 20 Jun 21 06:20 dec_test.txt [root@kalwa2 encypt_demo]# cat dec_test.txt I Love UxTechno!!!! [root@kalwa2 encypt_demo]#
The text in dec_test.txt is the same as in uxtechno.txt.
2. Hashing
Steps:
- Create a file uxtechno.txt with a line in it : I Love UxTechno!!!!
[root@kalwa2 encypt_demo]# cat uxtechno.txt I Love UxTechno!!!! [root@kalwa2 encypt_demo]#
2. Now Let’s hash this file to use a digital signature . In this case we are using MD5 as our hashing algorithm.
[root@kalwa2 encypt_demo]# openssl dgst -md5 -c -hex -out uxtechno.md5 uxtechno.txt [root@kalwa2 encypt_demo]# ls -ltr total 8 -rw-r--r--. 1 root root 20 Jun 21 06:19 uxtechno.txt -rw-r--r--. 1 root root 67 Jun 21 06:28 uxtechno.md5 [root@kalwa2 encypt_demo]# cat uxtechno.md5 MD5(uxtechno.txt)= b2:01:3d:34:52:07:67:e5:d8:a6:5f:d7:36:02:ad:95 [root@kalwa2 encypt_demo]#
Now if you make minor change in the “uxtechno.txt” & if you apply the above command then the MD5 hash will be different which proves the changes made to the file.
Leave a Reply