Public-key (asymmetric) Cryptography using GPG (2024)

GNU Privacy Guard (GPG, also called GnuPG) is a free encryption software you can use to encrypt and decrypt files. While the documentation for GnuPG is excellent, this is a quick cheatsheet on how to get started with GPG.

Mac

You need homebrew to be able to install gpg on Mac . If you don’t have homebrew installed, you can learn how to do that here. After that, it is a one line command.

brew install gnupg

Windows

There are many ways to install gpg on windows. Perhaps the easiest way to is to go to GnuPG site and use the simple installer for the current GnuPG.

Public-key (asymmetric) Cryptography using GPG (2)

Red Hat / CentOS

yum install gnupg

Ubuntu / Debian

If you are using these Linux distributions, you might want to change the commands in this tutorial to gpg2 after using the command below. You can find more infomation on this here.

sudo apt-get install gnupg2

GPG uses a method of encryption known as public key (asymmetric) cryptography, which provides a number of advantages and benefits. In a public key (asymmetric) encryption system, any person can encrypt a message using a public key. That encrypted message can only be decrypted with the corresponding private key. This section just goes through the GPG commands to do this. If you don’t understand asymmetric encryption, there is a wonderful youtube video on it here.

Generating Key Pair (Private and Public Keys)

1) Create your keys. This will generate a key pair. One is a private key which you need to keep safe and a public key which you can share with other people.

gpg --gen-key
Public-key (asymmetric) Cryptography using GPG (3)

2) You will have to enter a password. Keep it somewhere safe.

Public-key (asymmetric) Cryptography using GPG (4)

3) Export your public key. In this case, richter is the name of my public key. It will be whatever you named your key in step 1.

gpg --export --armor richter > richterPublicKey.asc
Public-key (asymmetric) Cryptography using GPG (5)

4) Send the public key you exported to another person.

Public Key Holder

1) Import another persons public key. You need to substitute richterPublicKey for the public key you wish to import.

gpg --import richterPublicKey.asc
Public-key (asymmetric) Cryptography using GPG (6)

2) Trust the public key. This will prevent GPG from warning you every time you encrypt something with that public key. You need to substitute richter with the name of your public key.

gpg --edit-key richter
Public-key (asymmetric) Cryptography using GPG (7)

Enter trust

Public-key (asymmetric) Cryptography using GPG (8)

Enter 5 , y , and then quit

Public-key (asymmetric) Cryptography using GPG (9)

3) This step shows how to encrypt a file (in this case, I encrypted a file superSecret.txt).

gpg --encrypt --recipient richter superSecret.txt
Public-key (asymmetric) Cryptography using GPG (10)

4) Transfer the encrypted file to the private key holder.

Private Key Holder

After receiving the file, you can decrypt the file. You will have to enter your password.

gpg --output superSecret.txt --decrypt superSecret.txt.gpg
Public-key (asymmetric) Cryptography using GPG (11)

Keep in mind that you can also decrypt multiple files using the following command.

gpg --decrypt-files *.gpg

Public Keys

You can view a list of public keys in your keyring as well as the name and email address associated with each key

gpg --list-keys
Public-key (asymmetric) Cryptography using GPG (12)

Private Keys

The following command will list the private keys in your keyring. This will show the private keys you have (including the one you created or imported earlier)

gpg --list-secret-keys
Public-key (asymmetric) Cryptography using GPG (13)

You can also delete keys from your keyring.

Remove Public Key

gpg --delete-key "User Name"
Public-key (asymmetric) Cryptography using GPG (14)

Note that if you try to delete a public key when you have its associated private key you will run into an error.

Public-key (asymmetric) Cryptography using GPG (15)

Remove Private Key

gpg --delete-secret-key "User Name"
Public-key (asymmetric) Cryptography using GPG (16)

Export a Secret Key

You can also export your secret key.

gpg --export-secret-keys richter > privateKey.asc
Public-key (asymmetric) Cryptography using GPG (17)

Import Secret Key

gpg --import privateKey.asc
Public-key (asymmetric) Cryptography using GPG (18)

You will need to make sure that you also ultimately trust a key.

gpg --edit-key orysya

enter trust

Public-key (asymmetric) Cryptography using GPG (19)

Enter 5 , y , and then quit

Public-key (asymmetric) Cryptography using GPG (20)

You can check this by using the command

gpg --list-secret-keys
gpg --list-keys
Public-key (asymmetric) Cryptography using GPG (21)

Keep in mind that you could also automate the trusting process.

expect -c "spawn gpg --edit-key {KEY} trust quit; send \"5\ry\r\"; expect eof"

I hope you find this tutorial useful. If you any questions or thoughts on the tutorial, feel free to reach out in the comments below or through Twitter.

Public-key (asymmetric) Cryptography using GPG (2024)

FAQs

Public-key (asymmetric) Cryptography using GPG? ›

In Asymmetric encryption, there is a pair of keys, one public and one private. The owner can share the public key with anyone whosoever wants to send the files in an encrypted format. That encrypted file is then sent back to the owner and that can only be decrypted by the corresponding private key.

How to encrypt with GPG public key? ›

  1. Step 1: Generate a GPG keypair. ...
  2. Step 2: Make your GPG public key available to the other party. ...
  3. Step 3: (For sender) Retrieve the message recipient's public key. ...
  4. Step 4: (For sender) Encrypt the message. ...
  5. Step 5: (For sender) Signing the message. ...
  6. Step 6: (For receiver) Decrypt the message.
Sep 27, 2017

What is the public key in GPG key? ›

GnuPG uses public-key cryptography so that users may communicate securely. In a public-key system, each user has a pair of keys consisting of a private key and a public key. A user's private key is kept secret; it need never be revealed. The public key may be given to anyone with whom the user wants to communicate.

Do people still use GPG? ›

GPG is in use today by journalists, business leaders, universities, and others who wish to keep the transmission of messages and data secure. The primary issues with GPG continue to be user acceptance, key handling, and the lack of understanding surrounding the complexity of key creation and exchange.

How to generate public key in GPG software? ›

How to Generate a Public-Private Key Pair
  1. A desktop application, for example: Mac OS: GPG Suite. Windows: GPG4Win (EXE)
  2. The gpg command line utility: Generate a new keypair: gpg --full-generate-key --openpgp. Copy. Export the keypair to a file (use the same email address that you used for generating the key pair):

Is GPG symmetric or asymmetric? ›

GPG uses a method of encryption known as public key (asymmetric) cryptography, which provides a number of advantages and benefits. In a public key (asymmetric) encryption system, any person can encrypt a message using a public key. That encrypted message can only be decrypted with the corresponding private key.

How do I send a public key to GPG? ›

To send your public key to a correspondent you must first export it. The command-line option --export is used to do this. It takes an additional argument identifying the public key to export. As with the --gen-revoke option, either the key ID or any part of the user ID may be used to identify the key to export.

What are the criticism of GPG? ›

One of the basic criticisms of GPG is around it's use of long term keys and lack of forward secrecy. This is actually a feature not a bug. One can be certain that a GPG key will decrypt a data that has been encrypted with it in the future.

Which is better PGP or GPG? ›

PGP is closed-source and proprietary, while GPG is open-source and free software. Meaning the former typically requires licensing fees, while the latter doesn't. You're free to view and modify the GPG source code.

How long do GPG keys last? ›

Depending on how long you want your key to be valid, you can set an expiration date for it. By default, Passwords and Keys sets all keys to be valid forever. That is, the keys never expire. The expiration date on a key can be changed anytime, even after the key has expired.

Do I need a passphrase for a GPG key? ›

It is your choice. A good passphrase is absolutely critical when using GnuPG. Any attacker who gains access to your private key must bypass the encryption on the private key. Instead of brute-force guessing the key, an attacker will almost certainly instead try to guess the passphrase.

What is the difference between SSH and GPG key? ›

Generating a GPG signing key is more involved than generating an SSH key, but GPG has features that SSH does not. A GPG key can expire or be revoked when no longer used. GitHub shows commits that were signed with such a key as "Verified" unless the key was marked as compromised. SSH keys don't have this capability.

How do I create my own public key? ›

To generate an SSH private/public key pair for your use, you can use the ssh-keygen command-line utility. You can run the ssh-keygen command from the command line to generate an SSH private/public key pair. If you are using Windows, by default you may not have access to the ssh-keygen command.

Is it possible to encrypt a public key? ›

Public key cryptography is a method of encrypting or signing data with two different keys and making one of the keys, the public key, available for anyone to use. The other key is known as the private key. Data encrypted with the public key can only be decrypted with the private key.

How to encrypt using password GPG? ›

Symmetric encryption (-c) is the simplest way to encrypt a file with gpg: just provide a password at encryption time. To decrypt, provide the password again. Binary encrypted files are created with the suffix . gpg , whereas ASCII encrypted files have the suffix .

Top Articles
Gartner Predicts AI Software Will Grow To $297 Billion By 2027
16 Quick Tips That'll Help You Stand Out in a Group Interview
Express Pay Cspire
Irela Torres Only Fans
Arcanis Secret Santa
Propnight Player Count
Double Helicath Clan Boss
Faketoks Twitter
Momokun Leaked Controversy - Champion Magazine - Online Magazine
Fairwinds Shred Fest 2023
Seafood Bucket Cajun Style Seafood Restaurant South Salt Lake Menu
Yovanis Pizzeria - View Menu & Order Online - 741 NY-211 East, Middletown, NY 10941 - Slice
Super Nash Bros Tft
Nextdoor Myvidster
Levidia 2019
Do you want to do a backbend?
Icy Veins Necromancer Diablo 4
Descargar AI Video Editor - Size Reducer para PC - LDPlayer
Onderdelen | Onderdelen en services
Convert liters to quarts
Spaghetti Models | Cyclocane
SEBO (UK) Ltd on LinkedIn: #sebouk #commercialcleaning #cleaning #floorcleaning #carpetcleaning
Shadbase Get Out Of Jail
Zen Leaf New Kensington Menu
Luciipurrrr_
Emerge Ortho Kronos
Craigslist Swm
Contoured Fowl Feather Wow
Modesto Personals Craigslist
Cal Poly 2027 College Confidential
Rachel Campos-Duffy - Net Worth, Salary, Age, Height, Bio, Family, Career
Find The Eagle Hunter High To The East
Locals Canna House Deals
Hibbett, Inc. Stock (HIBB) - Quote Nasdaq- MarketScreener
Hospice Thrift Store St Pete
454 Cubic Inches To Litres
Adult Theather Near Me
O2 eSIM guide | Download your eSIM | The Drop
Entourage Yearbook Login
Arsenal’s Auston Trusty: Inspired by Ronaldinho, World Cup dreams and Birmingham loan
Santa Cruz Craigslist Cars And Trucks - By Owner
Game On Classroom 6X
New York Rangers Hfboards
Watkins Brothers Funeral Homes Macdonald Chapel Howell Obituaries
Urgent Care Pelham Nh
Experity Installer
What is Landshark Beer?
Sound Of Freedom Showtimes Near Wellborne Cinema
Trivago Anaheim California
Bitmain Antminer S9 Review All You Need to Know
Saybyebugs At Walmart
Unblocked Games Premium 77
Latest Posts
Article information

Author: Manual Maggio

Last Updated:

Views: 5638

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.