Using GnuPG for encryption and decryption

On Ubuntu install with:

apt-get install gnupg

First generate private and public key:

gpg --gen-key

Generating this key can take some time, because it needs enough randomness.

Store your public key in a file:

gpg -a --export

Although it is not necessary to store this public key, you usually will provide this public key to other people, see for example my public key.

Import public keys from other people by

gpg --import my-friend.pub

Now encrypt a message for my-friend:

gpg -aesr my-friend your-file

These options have the following effect:

  • -a: create base64 encoded output (“ASCII armored”). This is not necessary, so you can skip this option. If skipped the output is binary.
  • -e: encrypt
  • -s: add signature. This is not necessary. You could drop this option from above.
  • -r: recipient, here your-friend

Decrypting a file is the easiest part. Just type

gpg encrypted-file
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s