Encrypting tar archives on the fly

I'm pretty sure there are more elegant ways to do on the fly encrypting but, since I am a gpg user, this has proven to be quick and handy.

Encrypting the archive

Whenever I need to encrypt a tar archive I simply create it with the following command:

$> tar cvf - /directory/to/archive | gpg -c > /my/tar/file.tar.gpg

I'm asked to type a passphrase (which is not the same passphrase I use for my gpg key) and the result is a gpg encrypted archive.

Please note that the -c option tells gpg to encrypt with a symmetric cipher.

Decrypting the archive

To decrypt:

$> gpg -d /my/tar/file.tar.gpg | tar xvf -

I just type the passphrase used when encrypting the archive and I'm done; all my files have been extracted.