Tuesday, August 14, 2012

HowTo Encrypt And Decrypt Files With A Password

To encrypt and decrypt files with a password, use gpg command. It is an encryption and signing tool for Linux/UNIX like operating system such as FreeBSD/Solaris and others.


GnuPG stands for GNU Privacy Guard and is GNU's tool for secure communication and data storage. It can be used to encrypt data and to create digital signatures. It includes an advanced key management facility.

Encrypting a file in linux

To encrypt a single file, use command gpg as follows:

$ gpg -c filename

To encrypt linuxhowto.in.txt file, type the command:

$ gpg -c linuxhowto.in.txt

Sample output:
Enter passphrase:<YOUR-PASSWORD>
Repeat passphrase:<YOUR-PASSWORD>

This will create a linuxhowto.in.txt.gpg file. Where,

  • -c : Encrypt with symmetric cipher using a passphrase. The default symmetric cipher used is CAST5, but may be chosen with the --cipher-algo option. This option may be combined with --sign (for a signed and symmetrically encrypted message), --encrypt (for a message that may be decrypted via a secret key or a passphrase), or --sign and --encrypt together (for a signed message that may be decrypted via a secret key or a passphrase).
Please note that if you ever forgot your password (passphrase), you cannot recover the data as it use very strong encryption.

Decrypt a file
To decrypt file use the gpg command as follow:

$ gpg linuxhowto.in.txt.gpg

Sample outputs:
gpg linuxhowto.in.txt.gpg
gpg: CAST5 encrypted data
Enter passphrase:<YOUR-PASSWORD>

Decrypt file and write output to file vivek.info.txt you can run command:

$ gpg myfinancial.info.gpg –o vivek.info.txt

Also note that if file extension is .asc, it is a ASCII encrypted file and if file extension is .gpg, it is a binary encrypted file.

1 comment:

  1. Excellent, I was looking for this information a few days ago, but it is still important to me. Now, I have another problem, I could not open the txt file. But, thank God I did it and I was able open .txt file https://wikiext.com/txt with the help and advice of this site. Every time, I am increasingly convinced, that any problem can be solved by searching on the internet!)))