How to check the Public Key Algorithm used for a given gpg key (ie: RSA vs DSA) - Michael Altfield's Tech Blog (2024)

How to check the Public Key Algorithm used for a given gpg key (ie: RSA vs DSA) - Michael Altfield's Tech Blog (1)

By Michael Altfield, on October 1st, 2017

Today I discovered how to validate the Public Key Algorithm that's used for a given gpg key. Unfortunately, it's extremely unintuitive & took quite a bit of digging to figure out how. So I'm leaving this here in hopes it helps someone in their future searches.

Assuming you have a public key file exported to a file named 'pubkey.asc', type this command from the same working directory as the 'pubkey.asc' file:

gpg --list-packets pubkey.asc

Or if the key is in your keyring, type this, replacing my key's fingerprint ID for yours:

gpg --export 'B162 9E1F 1737 EC4F 74C9 E923 1EF1 68D2 68C4 0535' | gpg --list-packets

The output is metadata about the public key, including the lines:

:public key packet: version 4, algo 17, created 1232569004, expires 0... keyid: 1EF168D268C40535

and

:public sub key packet: version 4, algo 16, created 1232569004, expires 0... keyid: EADF81259040F433

The first block is the master key. This key is typically used for signatures only.

The second block is a subkey. This key is typically the encryption key.

In each block, you'll see the lines "version X, algo Y".

The version refers to the Public-Key packet OpenPGP version, as defined in RFC #4880, section 5.5.2. Version 3 is deprecated; you should be using Version 4.

The "algo Y" is what we want. Y will be a number that maps to a specific Public-Key Algorighm, as defined in RFC #4880, section 9.1.

For example, if you see "algo 1", "algo 2", or "algo 3", then the key is using RSA.

If you see "algo 17", then you are using DSA (Digital Signature Algorithm). If you see that this key is using < 2048 bits, then you should deprecate & replace your key. DSA < 2048b was declared "Disallowed" by NIST in November 2011.

Related Posts

How to check the Public Key Algorithm used for a given gpg key (ie: RSA vs DSA) - Michael Altfield's Tech Blog (2)
Eavesdropping Analysis of PGP Metadata
How to check the Public Key Algorithm used for a given gpg key (ie: RSA vs DSA) - Michael Altfield's Tech Blog (3)
Mitigating Poisoned PGP Certificates (CVE-2019-13050)
How to check the Public Key Algorithm used for a given gpg key (ie: RSA vs DSA) - Michael Altfield's Tech Blog (4)
New Thumb Drive Encryption Procedure

How to check the Public Key Algorithm used for a given gpg key (ie: RSA vs DSA) - Michael Altfield's Tech Blog (5)

Hi, I’m Michael Altfield. I write articles about opsec, privacy, and devops

About Michael

How to check the Public Key Algorithm used for a given gpg key (ie: RSA vs DSA) - Michael Altfield's Tech Blog (2024)

FAQs

How to check public key in GPG? ›

Open Terminal . Use the gpg --list-secret-keys --keyid-format=long command to list the long form of the GPG keys for which you have both a public and private key. A private key is required for signing commits or tags.

Which algorithm is used for public key encryption? ›

Public Key Cryptography (asymmetric) uses encryption algorithms such as RSA and Elliptic Curve Cryptography (ECC) to create the public and private keys.

How do I find my public and private key in RSA? ›

➢ To create an RSA public/private key pair, here are the basic steps: 1- Choose two prime numbers, p and q such that p ≠ q . 2- Calculate the modulus, n = p × q. 3- Calcuate ϕ( n ) = ( p – 1 ) × ( q – 1 ). 4- Select integer e such that gcd (ϕ( n ), e) = 1 and 1 < e < ϕ( n ).

What is the RSA public key algorithm? ›

RSA is a popular and secure cryptographic algorithm that encrypts and decrypts data. It provides a secure method for transmitting sensitive data over the Internet. While RSA has some vulnerabilities, it is still utilized for various applications, like digital signatures to authenticate the source of a message.

What are the two most widely used public key algorithms? ›

RSA and ElGamal, the two public-key cryptosystems that we will examine, are both based upon number-theoretic problems. RSA is based upon the fact that it is easy to multiply together two large primes but it is hard to factor a large integer.

What is the most widely used public key algorithm? ›

The Rivest-Sharmir-Adleman(RSA) algorithm is the cryptography system that is used for public key cryptography, which is commonly used when sending secure and sensitive data over an insecure network like the internet.

What are the two types of keys used in public key encryption? ›

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 decrypt RSA value? ›

To decrypt an RSA ciphertext given the private key (d), ciphertext (c), and the public exponent (e), you can use the following steps: Compute the modulus (n) from the private and public keys using the equation n = p * q, where p and q are prime numbers and d is the private exponent.

What is the public key in gpg? ›

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.

How do I use public key in gpg? ›

Export Your Public Key

Send the public-key. gpg file to the recipient in an email or copy and paste the contents of the public-key. gpg file. The recipient should import the public key and validate it in order to use it to decrypt a message sent by you.

How do I get my public key from my GPG Keychain? ›

To export your public key, select your key in GPG Keychain Access and then click Export in the menu. Do not select “Allow secret key export”; your secret key should never be given to anybody. Click save to export your public key as an asc file.

Top Articles
Latest Posts
Article information

Author: Nathanial Hackett

Last Updated:

Views: 5891

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.