This repository demonstrates the use of GPG.
We'll simulate 2 parties: bob and alice.
Every time you perform actions as one of them, you need to set the GNUPGHOME
enviroment
variable to their directory.
We'll do a simulation in which we have 2 persons: Bob and Alice. In this simulation, Alice sends an encrypted message to Bob.
We'll start working with bob.
$ export GNUPGHOME=$PWD/bob
$ gpg --full-generate-key
Answer the questions. For email, write [email protected]
After this, you'll see that the bob
directory is filled with some files.
This is bob's private key, plus some other stuff.
Now we want to export Bob's public key so that Alice can import it.
$ gpg --output bob.key --export [email protected]
Now, as Alice, let's import Bob's public key.
$ export GNUPGHOME=$PWD/alice
$ gpg --import bob.key
Now, as Alice, let's encrypt a message with Bob's public key:
$ gpg --encrypt -r [email protected] message.txt
This will generate a message.txt.gpg
file, which is the encrypted message.
The -r
stands for receipient
, and it tells gpg with what public key to encrypt the message.
Now, as Bob, let's decrypt the message:
$ gpg -d message.txt.gpg
Now let's do this again, this time, in addition to encrypting the message, we want to sign it as Alice, so that Bob can be sure that Alice is the one that sent this message.
First, as Alice, generate a key-pair, as we've done with Bob. Then, import that public key with Bob, as we've done with Alice.
Now, encrypt the message as such:
$ gpg --encrypt --sign -r [email protected] message.txt
Decryption is done the same.