Password Protected tar files

There can be cases when you want to password protect the tar files. There are two ways you can do it.

First Method Using SSL and Salt:

Encrypt:

tar -cj directory | openssl des3 -salt > encrypted.tarfile

Decrypt:

cat encrypted.tarfile | openssl des3 -d -salt |tar -xvj

Second Method Using GPG:

Encrypt:

gpg -c

It will then ask for the password, you can type the password and retype it and it will generate the file having .gpg extension which is an encrypted file.

Decrypt:

gpg