0Pricing
Cryptology Academy · Lesson

GPG for Asymmetric File Encryption

Use GPG to encrypt files for specific recipients, sign content, and manage the GPG key ring.

GPG for Asymmetric File Encryption is a free Cryptology Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

GPG Overview and Purpose

GNU Privacy Guard (GPG) implements the OpenPGP standard (RFC 4880) for asymmetric file encryption and digital signatures. It enables two fundamental operations: encrypting a file so only the intended recipient can decrypt it, and signing a file so others can verify its authenticity and integrity. GPG is the standard tool for secure file transfer and software release signing.

Generating GPG Keys

GPG key generation is interactive with gpg --gen-key or scriptable with gpg --quick-gen-key. Modern GPG defaults to ed25519 for signing and cv25519 (Curve25519) for encryption, creating a primary signing key and a subkey for encryption. The --full-gen-key option provides full control over key type, size, and expiration date for users who need custom configurations.

GPG Key Types Comparison

RSA 4096-bit GPG keys are compatible with all OpenPGP implementations and provide strong security. ECDSA with Curve25519 (Ed25519 for signing, Cv25519 for encryption) produces smaller keys and faster operations while maintaining equivalent security. Legacy DSA keys are limited to SHA-1 digests in older implementations and should not be used. New keys should use Curve25519-based types.

Exporting and Sharing Public Keys

After generating a key pair, export your public key for distribution: gpg --armor --export your@email.com outputs an ASCII-armored public key block. Share this file with anyone who should encrypt files to you or verify your signatures. Recipients import your public key with gpg --import publickey.asc before they can encrypt or verify.

Encrypting Files for Recipients

To encrypt a file for a specific recipient: gpg --encrypt --recipient recipient@email.com --output secret.gpg plaintext.txt. GPG uses the recipient's public key to encrypt the file session key and encrypts the file with AES-256 (or the negotiated cipher). Only the recipient, holding the matching private key, can decrypt the file session key and recover the plaintext.

Creating Detached Signatures

A detached signature (gpg --detach-sign --armor file.tar.gz) creates a separate .asc file containing the signature. The original file is unchanged. Recipients verify with gpg --verify file.tar.gz.asc file.tar.gz. Detached signatures are the standard for software releases, allowing signature verification without decrypting or modifying the distributed file.

Verifying Signatures

Signature verification confirms that a file was signed by the claimed key and has not been modified since signing. gpg --verify signature.asc file outputs the key fingerprint, user ID, and whether the signature is good or bad. The security depends on correctly trusting the signer's public key: a valid signature from an untrusted or unverified key provides little assurance.

Passphrase-Protected Private Keys

GPG encrypts the private key with a symmetric cipher derived from a passphrase before storing it. Without the passphrase, an attacker who obtains the private key file cannot use it. GPG uses a key derivation function to derive the encryption key from the passphrase. The passphrase should be long and memorable but not used elsewhere, as all your encrypted files are protected by it.

GPG Key Server Operations

GPG key servers host public keys for discovery. gpg --send-keys KEYID --keyserver hkps://keys.openpgp.org uploads your public key. Others can search and import with gpg --recv-keys KEYID. Key servers synchronize with each other, providing global availability. Modern key servers like keys.openpgp.org require email verification before publishing, preventing key spam attacks.

Key Expiration and Revocation

Setting an expiration date on your key provides automatic protection if you lose control of it without creating a revocation certificate. When a key expires, GPG warns users encrypting to it. If your key is compromised, immediately publish a revocation certificate (created at key generation time) to key servers: gpg --import revocation.cert and gpg --send-keys. This prevents further encryption to the compromised key.

GPG in Automated Workflows

GPG can operate non-interactively in scripts using --batch and --yes flags and providing passphrases via --passphrase-fd for reading from a file descriptor. GPG agent (gpg-agent) caches the passphrase for a configurable duration, allowing automated re-use. For CI/CD pipelines, key material should be stored in secrets management systems, not in source code or environment variables.

GPG Encryption Command

Which GPG command encrypts a file for a specific recipient using their public key?

GPG File Encryption Recap

GPG recap: generate key pairs (prefer Curve25519), export and share public keys, encrypt with recipient's public key (--encrypt --recipient), sign files separately with detached signatures (--detach-sign), verify signatures with --verify, protect private keys with passphrases, set expiration dates and prepare revocation certificates, and use key servers for public key discovery and distribution.

Frequently asked questions

Is the “GPG for Asymmetric File Encryption” lesson free?

Yes — the full text of “GPG for Asymmetric File Encryption” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.

What will I learn in “GPG for Asymmetric File Encryption”?

Use GPG to encrypt files for specific recipients, sign content, and manage the GPG key ring. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cryptology Academy?

No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “GPG for Asymmetric File Encryption” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cryptology Academy lesson?

Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. GPG for Asymmetric File Encryption
  2. The age Encryption Tool: Modern GPG Alternative
  3. Encrypted Containers with VeraCrypt
  4. Secure Deletion and Key Destruction
← Back to Cryptology Academy