Pages

Monday, March 11, 2013

Encrypt the file or source code

GPG stands for Gnu Privacy Guard, is a tool used to sign and encrypt data. Here I'm giving a simple usage of this tool.


Usecase: We have a file on linux server, which needs to be encrypted and delivered to another machine.

Solution 1:- Encrypt a file
  • By default every linux server comes with "gpg" tool. You can verify by running the command "which gpg"
  • Use gpg command to encrypt your file
           cd TO_YOUR_FILE_LOCATION   (I need to encrypt a file named TEST)
           
           gpg -c TEST (It will ask for the passphrase/password, give a strong one and remember it)
           It creates a file named TEST.gpg, which is encrypted. You can take a look at the content of this file
  • Using gpg command for decryption
          Now I have transferred this encrypted file (TEST.gpg) to another server where gpg utility is available and run below command to decrypt it
         gpg -o TEST-d TEST.gpg
      
          Where -o option tells to create a file TEST, instead of printing output on console

Solution 2:- Encrypt the Source code or a folder
  • cd TO_YOUR_FILE_LOCATION   (I need to encrypt a file named TEST)
  • tar -zcf abc.tgz abc
  • Follow the command to encrypt
       
Strengthening encryption using AES256 cipher algorithm

Command to Encrypt
gpg --symmetric --cipher-algo aes256 -o abc-src.tar.gz.gpg abc-src.tar.gz
Enter passphrase: *******
Repeat passphrase: *******

Command to decrypt
gpg -d -o abc-src.tar.gz  abc-src.tar.gz.gpg
gpg: AES256 encrypted data
Enter passphrase: ******* 

No comments:

Post a Comment