GPG keys and how to use them - we explain on our fingers

12/20/23

Post preview banner

What is GPG?


It is a cryptographic program for encryption and digital signature.

GPG is based on the idea of two encryption keys for each user. Each person has their own private key and public key. The public key can decrypt the information encrypted by the private key.

How does it work?

So, if you want to send a secret message or file to someone, you use their public key to encrypt the information. Only the owner of the private key can decrypt it.

Public key exchange allows you to communicate securely. You can encrypt your messages with your conversation partner's key, and he decrypts them with his private key. And vice versa.

A private key is also able to sign files like a digital signature. This can be verified using the public key.

History


  • 1997: Werner Koch, a German programmer, developed GPG (GNU Privacy Guard) as a free alternative to PGP. GPG became part of the GNU project and used open standards.
  • 2000s: GPG became a standard for many operating systems and development tools, as well as the basis for various applications and libraries that support encryption and digital signatures.
  • Today: GPG is widely used for email security, authentication, and digital signatures in a variety of applications. It is supported by many operating systems and is part of many cryptographic solutions.

Keys


You need to have the recipient's public key to encrypt the file, and the recipient must have your public key to decrypt it. There is no danger in making your public keys just the public key

Public key (or Public key/Public key)

It's your digital business card. Share it with anyone you want to communicate with securely. Basically, it's your number for secure messaging.

Public key (or Public key/Public key)
Public key (or Public key/Public key)

Private key

He needs to be watched closely. It deals with encrypting and decrypting messages. It is better to keep it in a safe place, for loss may cause problems.

Private key
Private key

Symmetric and Asymmetric Encryption


GPG can be used for symmetric encryption, but its main application is in asymmetric data encryption. In a nutshell: in symmetric encryption, one key is used to encrypt and decrypt messages (e.g., a specific character corresponding to a specific letter). In the case of asymmetric encryption, two keys are used - a public key and a private key.

Symmetric Encryption: It is like a lock with one key. The same key is used to close and open the door. For example, if your friend sends you an encrypted message, you need the same key to read it.

Asymmetric Encryption: There are two keys, like two locks. One key (the public key) is used to encrypt messages and the other (the private key) is used to decrypt them. You can give the whole world your public key, and keep the private key secret. Only the owner of the private key will be able to unlock the "lock" and read the message. Simply put, if someone encrypts a message with your public key, only your private key will decrypt it.

So symmetric is one key for all operations, asymmetric is a pair of keys, each with its own role.

Kleopatra. A simple and convenient option on Linux,Windows,Tails.


It's no secret that working through a terminal may not suit every person, and interacting with GPG in a Linux terminal can seem complicated and confusing.

We will look at an open source application designed to work with the GPG toolkit in a graphical shell. It is a godsend for beginners and those who prefer to avoid using the mysterious black command line window. Due to the cross-platform nature of the application, this article will be useful for Windows, Linux (Tails too) and FreeBSD users.

In various Unix-based operating systems, Cleopatra is easily accessible through repositories. For example, to install on Debian, just use the command:

sudo apt-get install kleopatra.

If you prefer the Windows operating system, the program comes with the GPG4Win package.

The starting point of GPG is to create your own key pair. The public key can be distributed widely, while the secret key is stored in a secure location. The secret key is used to sign information on behalf of the owner and decrypt encrypted messages.

Kleopatra GPG
Kleopatra GPG

Here are a few of the benefits of using Kleopatra GPG:

  1. Kleopatra provides a graphical user interface, which makes working with GnuPG more convenient for those who prefer visual interaction.
  2. Kleopatra simplifies the creation, import, export and management of encryption keys. It allows users to easily add and remove keys and manage them in general.
  3. With Kleopatra you can easily encrypt and decrypt files without typing commands in the terminal. Just select the file, click on the appropriate item in the menu, and Kleopatra will perform the necessary steps.
  4. Kleopatra also makes it easy to sign documents using GnuPG. This is an important feature for data authentication.
  5. Kleopatra can integrate with some email clients to securely send and receive encrypted and signed emails.
  6. Kleopatra allows you to perform key certification operations, which increases the trust in your public key.
  7. Kleopatra provides reports on executed operations, which is useful for tracking and analyzing key and data activities.
  8. Kleopatra is available for a variety of operating systems including Windows and Linux, ensuring ease of use across platforms.

Kleopatra. Installation on Linux


Open the terminal and enter:

sudo apt-get install kleopatra.

Update all packages after installation

Sudo apt-get update

Run it through the command:

Kleopatra
Kleopatra main menu after launching the application
Kleopatra main menu after launching the application

Kleopatra. Installation on Windows


Go to the Gpg4win website and select the free version of GPG4WIN.

Click on Download
Click on Download

After that we are redirected to the page with automatic download of the file. Download and run it:

  • https://cdn-seo.rulook.com/1d034c5f-7b11-40ec-b765-cc94f77ee98f.png
  • https://cdn-seo.rulook.com/20b692dc-a57a-4b5b-afe9-c1ad9bd2ebf6.png
  • https://cdn-seo.rulook.com/35ec122d-538e-46ed-8c6f-0ae65ef6c14b.png
  • https://cdn-seo.rulook.com/39b76878-5923-4e40-89cb-06059b8cf1a8.png

Kleopatra. Key creation


Once the setup is complete, you will see this window. Click "New Key Pair".

New OpenPGP key pair
New OpenPGP key pair

On the screen that appears below, enter your name and email address.

Enter name and mail (Name will be public, it is better not to write your real name)
Enter name and mail (Name will be public, it is better not to write your real name)

The password you enter does not participate in the encryption and decryption process; it serves as protection for your key, which is stored in a home folder on your computer. This password is necessary to prevent an attacker from accessing your private key in the event of physical access to your computer. An attacker will need to first guess or pick the password before they can use the private key. Therefore, it is important to create a strong password with different characters

Select additional parameters:

The default is RSA with a key of 2048 bits, but due to quantum technologies its reliability is decreasing. Elliptic curve algorithms such as brainpool provide high security with a shorter key length.

To create elliptic curve keys, choose ECDSA/EdDSA. Choose an algorithm, for example, brainpool. The key is created with an expiration date, which can be changed or disabled, making the key perpetual

Finalizing key creation
Finalizing key creation

Kleopatra. How to find your public key and save it


Click on your profile (in our case Dmitrievich Oleg) and select details:

Click for details
Click for details

Select export

Click on export
Click on export

And we get our public key

Click, copy and save to any text file you want
Click, copy and save to any text file you want
This is your public key that we've stored
This is your public key that we've stored

Kleopatra. How to find your private key and save it


Right click on your profile and select "Backup private keys"

Clicking
Clicking

Save our key in a convenient place:

Now we have both public and private keys
Now we have both public and private keys

Open the file with a text editor:

PRIVATE KEY
PRIVATE KEY

Kleopatra. Message encryption


Now let's encrypt the message using Notepad in the Kleopatra program. We will encrypt the message only for ourselves, so that only we can read it.

Let's start by navigating to "Notepad" in the Kleopatra toolbar. Then type in your message.

Notebook
Notebook

When your message is ready, you need to encrypt and sign it.

Click the "Recipients" tab.

Recipients
Recipients

Since we are encrypting this message for ourselves, we will select the Encrypt for me option. We don't have any other recipients to encrypt messages for now, so we'll leave this option unchanged.

Click to sign and/or encrypt the text
Click to sign and/or encrypt the text

The successfully converted message is now a random string of incoherent text. You can copy/paste and save it anywhere, and only I can decrypt it back to the original message.

Kleopatra. Message decryption


Now let's see how to decrypt an encrypted message back to its original state.

Suppose we have saved the message in a text file. Open Kleopatra, go to Notepad, and paste the encrypted message back into the text area.

The notebook at Kleopatra
The notebook at Kleopatra

Since the message is sent only for myself, and my private key is securely stored on this computer, I can easily decrypt it by simply using the "Decrypt / Verify Notepad" button

Message after transcription
Message after transcription

As you can see, the message has been decrypted. Since I "signed" the message on my behalf when encrypting it, it says "Valid signature from..." - so you can verify that the message is authentic and from the specified sender.

Let's do it again

To decrypt an encrypted message sent to you using your public key, you will need your own secret key. The process may be as follows:

  1. If you don't already have the sender's public key in Kleopatra, import it so that the application knows how to decrypt the message. You can import the key by opening the "File" tab and selecting "Import Certificates". Then specify the path to the public key file.
  2. Make sure that your secret key is added to Kleopatra. This is necessary so that the application can use it to decrypt messages. You can add a secret key through the "File" tab and selecting "Import Secret Keys".
  3. When you have the sender's public key and your secret key, Kleopatra should automatically use them to decrypt the message. Normally, if you have an encrypted message, just open it in Kleopatra and the program will automatically decrypt it using your keys.

Kleopatra. Receiving encrypted messages from other people


Next, consider a situation where we want our friend to be able to send us an encrypted message. To do this, we must give him our public key. Remember that we never want to share our secret key with anyone else.

Go back to the Certificates page and select the key pair you want to use to receive messages from that person.

There are several ways to export a public key. We will export only the text. To do this, double-click on the key pair.

This will open a dialog box with additional information about the key. Click the Export button

Public key
Public key

This is a public key block. You will share it with the people or services you want to receive encrypted messages from. This is what allows them to send you encrypted messages.

Once you send someone your public key, they will be able to send you messages. To decrypt messages sent to you, simply copy and paste them into notepad and decrypt them using your secret key as we did in the previous example (sending a message to yourself).

What is the easiest way to transfer your key to another person


The easiest way to send it is through self-deleting messages.

Go to the Privnote website and send the text we need in the input field

Click on Create note
Click on Create note

Now we have the possibility to send our key to the right recipient with a short link, the message will be deleted after reading it

Kleopatra. Sending an encrypted message


Next, consider the situation where you are trying to send an encrypted message to someone else. To do this, they must provide you with their public key.

For demonstration purposes, here is our comrade's public key.

-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: Идентификатор пользователя:	Kevin Agler <[email protected]>
Comment: Действителен с:	25.12.2023 2:05
Comment: Действителен до:	25.12.2026 12:00
Comment: Тип:	255-битный EdDSA (доступен секретный ключ)
Comment: Применение:	Подпись, Шифрование, Заверение идентификаторов пользователя
Comment: Отпечаток:	07CC02E39730E43595FCE3CBBD40B56DDC7B8C61


mDMEZYi5HxYJKwYBBAHaRw8BAQdASxia8+gBW3whrcrcgbdE5f9TPzvOxj6NarIP
ceS7nQO0IktldmluIEFnbGVyIDxLZXZpbkBwcm90b25tYWlsLmNvbT6ImQQTFgoA
QRYhBAfMAuOXMOQ1lfzjy71AtW3ce4xhBQJliLkfAhsDBQkFpXdxBQsJCAcCAiIC
BhUKCQgLAgQWAgMBAh4HAheAAAoJEL1AtW3ce4xhQukBALAJD9lCfTrMYXP25Voa
b7nShxKJG5Xe3753V/PqHhRaAP9GHuOSJ5uKEeBHMxwLdCbDHfiwp+06ze4KEkAk
p6hbCLg4BGWIuR8SCisGAQQBl1UBBQEBB0AmsiL4iiGEN8l1BTiQPc8B0GBLOEFA
sIRFukAJTE3rYAMBCAeIfgQYFgoAJhYhBAfMAuOXMOQ1lfzjy71AtW3ce4xhBQJl
iLkfAhsMBQkFpXdxAAoJEL1AtW3ce4xhuWcBAOY82LteTn7jvAD+4XW78dkB56OG
pMjOrjzO44AhUXy1AQCYtsXJWwsTXAXjH4HnXhUbKVI1mKupdcS8SNIPd62aAg==
=LcFY
-----END PGP PUBLIC KEY BLOCK-----</[email protected]>

The easiest way to import your public key is to save it as a text file. Open Notepad and paste my public key in there. Then save it as a .gpg file.

Click on import
Click on import

Paste the GPG key file we just created into Kleopatra. The program will ask if you want to "Confirm" the public key. If the key is confirmed, it means that you have verified the key fingerprint by comparing it with the fingerprint provided by the sender

Select the public key of our interlocutor
Select the public key of our interlocutor

For example, you can contact the owner of the public key and ask them for a fingerprint of the key. If it matches the fingerprint they showed you, you can confirm that the key is genuine. Otherwise, someone has sent you an invalid or counterfeit key.

For our purposes, you can simply validate the key. The fingerprint must match "07CC02E39730E43595FCE3CBBD40B56DDC7B8C61".

Now several keys will appear in the list of Kleopatra certificates. The first one should be your key pair, the second one should be the interlocutor's public key.

Dmitrievich is our pair of keys, and Kevin is our
Dmitrievich is our pair of keys, and Kevin is our

Back to the notepad. In this case, I have created a new key pair: private and public, for a person named "Billy Bob". Let's pretend that I am Oleg, and I need to send a message to Kevin. You can continue to use the private key you created earlier for yourself.

Enter the message you want only Kevin to see.

Click the Recipients tab. You can sign the message on your behalf if you want. In this example, I have disabled the "Encrypt for me" option. This means that once this message is encrypted, only the recipient will be able to decrypt it, and I will not be able to decrypt the message again by pretending to be Oleg.

Go to Notepad and click "sign".

Now the message is encrypted. I can send it to anyone, but only Kevin can read it using his secret key.

If I try to decipher the message, it fails. Remember that in this example, I am "Oleg", not "Kevin". Only I can decrypt a message from Oleg using my secret key.

You can encrypt a message to any number of people, only you need their public keys
You can encrypt a message to any number of people, only you need their public keys

Kleopatra. How to create a password-protected message


Now let's create a password protected message that can be read by anyone without a specific private key, as long as they know the password. To do this, go to Notepad and type your message.

Message content
Message content

Navigate to the recipients and select the bottom "Encrypt with password" checkbox.

We will be asked to enter the password after encrypting the message, enter it
We will be asked to enter the password after encrypting the message, enter it

Enter the password and click OK

You can now decrypt the message by simply typing "mypassword". Anyone you send the message to will be able to decrypt it using this password. Note that this is much less secure than encryption/decryption using private/public keys.

Below will be our passworded message, you can decrypt it via the password 123456789

-----BEGIN PGP MESSAGE-----

hF4DaW6P+nO+usgSAQdABXYihZkXgKz5p0ERVqzDP2VufslzZpeLZdajMJ7ocz8w
F434Zf0BF0C0mMH0XB3VuI2XOrRdsDWOIfrxqQ10cC53lHq1FU6W8xqHbHKkuCsk
jE0FCQIDCM5KaJPTYChL/7VeiFnQ8cPKpYl9Tqh8fb2ct/GpVceXXXSQFQdzsL6V
C/DSHuyL0onuPSPkuMAdD8DHVI2lXxtKdHL6kxTiNtTAXgEJAhCYZavtd7ZwAQ8o
rHha9JiSfLhZIWtjttwRYg3Auar0ZCTvyy9S4V1j/yOeeiltdLeMENAMmTqvSqSz
d4ZXKBD0zQPihWq+VrkcaHP0X80JcKf6BVDQcaRtWfhRPDwUuJMBSeCdBBIIppj1
zuznkKiYf5Zlph4FczkIDLHCrEhsxw1G3I+qb5QXSV+C4VqNHENOTIQmLJB2PE19
5TAZZplNhtr6QSmX2MYXC7kcRRFQQyt6xCiuRjx5hs4Wabsagx+f9vvVzwRvPuVI
iQa+dEGlZmkvLc+XyeTqqgyFLV5NOX86G8N6oL1BPMiM/iqAYKmtAOz6a2Fl9S2W
PUAIRGLgoFb1yt+SxztHEi26U9jMY2fd5rdOR9duV4Y=
=GzY/
-----END PGP MESSAGE-----

Kleopatra. How to sign a message


If you want to distribute a public message but prove that it was you who wrote it, you can create a signed PGP message.

For example, we wrote the following message:

Now I'm going to "sign" the message without encrypting it myself.

Now when I click on "Sign Notepad", I get the following output:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Всем привет! Это Олег! 
-----BEGIN PGP SIGNATURE-----

iHUEARYKAB0WIQRNsxvVXzP8ajAJNedh3chqCpgpqgUCZYlv2wAKCRBh3chqCpgp
qviIAP9E08FGBrZSLlwl/CQWFtFtrqup75p36yTrRs6my13spAEA7Ngo5HBVW1Kf
BwaYRqEnvVFzebP8MW03eH2+/jNAUAo=
=dhGu
-----END PGP SIGNATURE-----

As you can see, the message itself is still visible. However, there is a PGP Signature section. Anyone with Kleopatra and my public key can paste this into notepad and click "Decrypt/Verify Notepad" - this will verify the PGP signature with my public key and notify them that the message has been validated.

You can verify the signature via decryption, but that requires saving my public key:

-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: Идентификатор пользователя:	Дмитриевич Олег <[email protected]>
Comment: Действителен с:	24.12.2023 23:51
Comment: Действителен до:	24.12.2026 12:00
Comment: Тип:	255-битный EdDSA (доступен секретный ключ)
Comment: Применение:	Подпись, Шифрование, Заверение идентификаторов пользователя, SSH-аутентификация
Comment: Отпечаток:	4DB31BD55F33FC6A300935E761DDC86A0A9829AA


mDMEZYiZ5BYJKwYBBAHaRw8BAQdAZ2G6mmYuRRgb1fxHpLrXMyrDYIpfqYZEXqoC
g1O3rsu0MtCU0LzQuNGC0YDQuNC10LLQuNGHINCe0LvQtdCzIDxqZXp1czAwM0Bw
cm90b24ubWU+iJkEExYKAEEWIQRNsxvVXzP8ajAJNedh3chqCpgpqgUCZYiZ5AIb
IwUJBaRFLAULCQgHAgIiAgYVCgkICwIEFgIDAQIeBwIXgAAKCRBh3chqCpgpqmsm
AQDJLWvRZ8Iy5w3cZ2iBsvTwR0my/rrtojwPcVSzI0cfggD6AnWJ1QxtMqyeokml
nBrtNntHKov7tgyN4gU79TWzUAS4OARliJnkEgorBgEEAZdVAQUBAQdACt34kXLw
HVC9M0QBAj+A204XpilKjhG80fMf3hRzzVsDAQgHiH4EGBYKACYWIQRNsxvVXzP8
ajAJNedh3chqCpgpqgUCZYiZ5AIbDAUJBaRFLAAKCRBh3chqCpgpqvvWAQDsM+xU
cixUMclbjBuvH/9Fiu4MrHLAL9OZaJG7NGaCBAD/WCyylOPzlpgDkXQUHmhF7jb9
oGzMnrgvErKCVgavTwE=
=Jgpc
-----END PGP PUBLIC KEY BLOCK-----
</[email protected]>

Since I have my public key in Kleopatra, it can verify that the message was signed by Oleg and not some scammer.

Confirmation of the sender's seal - the message was sent exactly by Oleg
Confirmation of the sender's seal - the message was sent exactly by Oleg

Kleopatra. File encryption


I have a picture of my dogs, but it's top secret, so I want to prevent outsiders from accessing it.

If you have installed Kleopatra with context menu or shell extensions (which is the default option when installing Gpg4Win), you can right-click on the file you want to encrypt and select the "Sign and encrypt" option. On Windows 11, you may have to select the "Show more options" option first.

Select the key you want to use to sign the file and add the recipients you want to give access to the file. If you want the file to be accessible only to you using your secret key, simply select "Encrypt for me". In this example, I encrypted the file for myself and for Billy Bob.

Click the "Sign/Encrypt" button. The file is now encrypted.

Now you can see that I have an original file and an encrypted file. I can send the encrypted file to anyone, but only me and Billy Bob can open it. I can post it publicly anywhere without fear of someone else seeing my cool puppy. If you encrypt files just for yourself, make sure you delete the original file after encrypting it!

Kleopatra. Key Backup


To back up a key, simply right-click on the certificate in Kleopatra and select the "Backup secret keys" option. This will open a dialog box allowing you to save a backup key file.

Save it in a safe place. If you need to recover the key later, you can import this secret key back into Kleopatra using the Import button.

Kleopatra. Publishing the public key on the server


Sending your public key to the key server in Kleopatra is an important step to ensure the secure exchange of encrypted messages. Public keys are essential for encrypting messages, and having them on the key server brings several benefits:

  1. Key availability to other users: Placing your public key on the server makes it available to anyone who wants to send you an encrypted message. This simplifies the key exchange process, because other users do not need to specifically request your key - they can get it from the server.
  2. Key Update and Revocation: If you need to update your key or revoke it, sending new version or revocation information to the server helps other users keep up to date with changes.
  3. Centralized access: The Key Server serves as a centralized resource for finding and retrieving public keys, making the key exchange process more convenient and efficient.

This process keeps key information transparent and up-to-date, which is an important element of public key cryptography. Sending the public key to the server contributes to the simplicity and security of encrypted communications.

Comments

Advertisement:

ads