GPG
GPG

How To Use GPG to Encrypt and Sign Messages

GPG key ( GNU Privacy Guard) is a way to secure your online communications and verify your identity, it works by using a combination of public and private keys to encrypt and decrypt messages.

How Public Key Encryption Works :

Public key encryption is a type of encryption that uses a pair of keys to encrypt and decrypt messages. The two keys are known as the public key and the private key. The public key can be shared with anyone, while the private key must be kept secret.

To encrypt a message, the sender uses the recipient’s public key. This creates a unique ciphertext that can only be decrypted by the recipient’s private key. This means that only the person with the private key can read the message, even if the public key was used to encrypt it.

This type of encryption is called « public key » encryption because the public key can be shared openly, without compromising the security of the message. It is also known as « asymmetric » encryption because the two keys are not the same.

How to use GPG Key :

To use it, you will first need to install the GPG but it is installed by default in most distributions :

GPG

If for any reason it is not installed, you will installed like this :

On CentOS / RedHat :

[root@linux ~]# yum install gnupg2

On Ubuntu / Debian :

[root@linux ~]# apt-get install gnupg

Once it is installed, you will need to generate a GPG key pair, which consists of a private key and a public key.

The private key is used to decrypt messages that are encrypted with your public key and the public key is used to encrypt messages that only you can decrypt with your private key.

To generate a key pair, open a terminal or command prompt and run the following command :

[root@linux ~]# gpg --gen-key

You should then give answers for a few questions that will configure your key :

Your Real name

Your Email address

A pass phrase to protect your key ( it should be a complicated one )

Generate GPG key
Generate GPG key
Generate GPG key
Generate GPG key

A then a folder named .gnupg is created :

Generate GPG key

Il you want a full featured key generation dialog ( what kind of key you want, What keysize ..) use the command bellow :

Generate GPG key with gpg –full-generate-key

Once you have your key pair, you can use it to encrypt and decrypt messages. To encrypt a message, use the following command :

[root@linux ~]# gpg -e -r [recipient] [message file]

Replace [recipient] with the email address of the person you are sending the message to and [message file] with the path to the file containing the message you want to encrypt. This will create an encrypted version of the message, which can only be decrypted by the recipient using their private key.

To decrypt a message, use the following command :

[root@linux ~]# gpg -d [message file]

Replace [message file] with the path to the encrypted message file, this will decrypt the message and display it on the screen.

There are many more options and features available in GPG, including the ability to sign messages to verify their authenticity and the ability to manage multiple keys.

For more information, consult the GPG documentation.