DEV Community

Pavan Kumar Sadashiv
Pavan Kumar Sadashiv

Posted on

The Zero-BS Guide to PGP: Encrypt Messages & Files with Kleopatra

Whether you want to protect sensitive configuration files, communicate securely over public channels, or verify digital identities, PGP (Pretty Good Privacy) remains one of the gold standards of asymmetric cryptography.

However, running GnuPG (gpg) solely through terminal flags can be intimidating for beginners. That is where Kleopatra comes in. Kleopatra is an intuitive, open-source graphical front-end for Gpg4win (on Windows) and KDE (on Linux) that makes key management, file encryption, and digital signing visual and straightforward.

In this guide, you will learn how to set up Kleopatra, generate your keys, exchange public keys with collaborators, and encrypt/decrypt both text and files.


πŸ› οΈ Prerequisites & Installation

On Windows

Kleopatra is packaged with Gpg4win:

  1. Download the installer from the official site: gpg4win.org.
  2. Run the .exe file.
  3. During component selection, ensure Kleopatra is checked.
  4. Complete the installation.

On Linux (Debian / Ubuntu / Fedora)

Kleopatra is available in most default repositories:

# Ubuntu / Debian
sudo apt update && sudo apt install kleopatra

# Fedora
sudo dnf install kleopatra

# Arch Linux
sudo pacman -S kleopatra
Enter fullscreen mode Exit fullscreen mode

πŸ”‘ Step 1: Generate Your Key Pair

Asymmetric encryption uses two keys:

  • Public Key: Shared with everyone. People use this to encrypt messages sent to you.
  • Private Key (Secret Key): Kept strictly on your machine. You use this to decrypt messages and generate digital signatures.

Steps:

  1. Launch Kleopatra.
  2. Click New Key Pair (or navigate to File > New Key Pair...).
  3. Select Create a personal OpenPGP key pair.
  4. Enter your real name (or alias) and your email address.
  5. Click Advanced Settings:
    • Algorithm: Choose RSA with 4,096 bits, or select ECDSA/Ed25519 for modern elliptic-curve cryptography.
    • Valid until: Set an expiration period (1 or 2 years is standard practice for operational security). You can renew keys before they expire.
  6. Click OK, then click Create.
  7. Enter a strong, memorable passphrase when the Pinentry prompt appears.

πŸ’‘ Tip: Treat your passphrase like a master password. If someone gets your private key file, your passphrase is the only layer of defense preventing them from decrypting your data.

Once finished, Kleopatra will display your 40-character fingerprint. Your key will now appear under the My Certificates tab.


πŸ“€ Step 2: Export and Share Your Public Key

To receive encrypted messages, other people must have your public key.

Exporting via Clipboard (Quick Sharing):

  1. In Kleopatra, click your key under My Certificates.
  2. Click Export... (or right-click and choose Clipboard > Export).
  3. If copied to the clipboard, paste it to verify. It should look like this:
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBF+...
...
-----END PGP PUBLIC KEY BLOCK-----
Enter fullscreen mode Exit fullscreen mode

You can now paste this block into a README, pastebin, social profile, or email.

⚠️ CRITICAL SECURITY WARNING:
Never select Export Secret Keys... unless you are creating an offline backup for yourself. Never share your secret key with anyone.


πŸ“₯ Step 3: Import a Contact's Public Key

Before you can encrypt data for someone else, you need their public key.

  1. Copy your contact's ASCII-armored public key block to your clipboard.
  2. In Kleopatra, navigate to Tools > Clipboard > Certificate Import (or click the Import... icon on the toolbar and select their .asc file).
  3. Kleopatra will display an import confirmation dialog. Click OK.
  4. Right-click the newly imported key and choose Certify... to sign their key with your identity once you have verified their fingerprint over a secure channel.

The imported key will now live under the Other Certificates tab.


πŸ”’ Step 4: Encrypting Data

Scenario A: Encrypting a Text Message (The Notepad Tool)

  1. Click the Notepad button on the Kleopatra toolbar.
  2. Type or paste your plaintext message into the Notepad area.
  3. Switch to the Recipients tab below the text box:
    • Check Encrypt for others and click Add Recipient to select your recipient’s public key.
    • (Recommended) Check Encrypt for me so you will still be able to read the sent message later.
    • (Optional) Check Sign as to attach a digital signature proving the message originated from you.
  4. Click Encrypt Notepad.

Your plaintext is instantly transformed into an encrypted cipher block:

-----BEGIN PGP MESSAGE-----
hQGMA...
-----END PGP MESSAGE-----
Enter fullscreen mode Exit fullscreen mode

You can safely copy and paste this block into Slack, Discord, email, or a GitHub issue. Only the owner of the recipient key can read it.

Scenario B: Encrypting a File or Folder

  1. Click Sign / Encrypt... on the toolbar.
  2. Browse to and select the file (e.g., credentials.env or backup.tar.gz).
  3. In the setup window:
    • Check Encrypt for others and choose the recipient's key.
    • Choose whether you want an armored output (.asc) or binary output (.gpg).
  4. Click Sign / Encrypt.

πŸ”“ Step 5: Decrypting Data

Scenario A: Decrypting Text Messages

  1. Copy the entire encrypted block from -----BEGIN PGP MESSAGE----- to -----END PGP MESSAGE-----.
  2. Open Kleopatra and open the Notepad.
  3. Paste the block into the Notepad window.
  4. Click Decrypt / Verify Notepad.
  5. Enter your passphrase when prompted.
  6. The decrypted original message appears on screen with a green verification banner.

Scenario B: Decrypting Files

  1. Click Decrypt / Verify... on the toolbar.
  2. Select the encrypted file (.gpg, .pgp, or .asc).
  3. Enter your secret key passphrase.
  4. Kleopatra extracts the decrypted original file into your specified folder.

πŸ›‘οΈ Production Best Practices

  • Create a Revocation Certificate: If your private key is ever lost or compromised, a revocation certificate allows you to notify keyservers that the key is invalid. Right-click your key in Kleopatra and choose Backup Secret Keys..., storing this backup on an encrypted, air-gapped USB drive.
  • Always Verify Fingerprints: When importing public keys from colleagues, confirm the 40-character fingerprint through an out-of-band channel (e.g., a voice call or in person) to eliminate Man-In-The-Middle (MITM) attacks.
  • Do Not Forget Your Passphrase: OpenPGP does not have a "Forgot Password" button. If you lose your passphrase, any data encrypted with that key is permanently lost.

πŸš€ Wrapping Up

Kleopatra bridges the gap between rock-solid OpenPGP security and modern desktop usability. By understanding key generation, public key distribution, and basic file/text encryption, you can integrate true end-to-end privacy into your daily development workflow.

Have questions about subkeys, smart cards (like YubiKeys), or automating PGP in CI/CD? Drop a comment below!

Top comments (0)