gpg list key and display key details from a file (without importing the key)

Files with GPG keyspublic or private. Here is how to get more information without importing the keys.
GPG cli could give enough information for an explored key in a file:

  • public or private key
  • encrypted or unencrypted key
  • user id description (including email)
  • key id and issuer fpr v4
  • when the key was generated and when it will expire
  • the algo for the encrypted key
  • more

The key may be in binary or ascii format. No difference.
Here is the GNU GPG cli command:

gpg --list-packets < ./filewith.key

All examples below are made with gpg (GnuPG) 2.2.19.

Public key

A file with exported public key.

gpg --list-packets <./ahelpme.com.gpg
# off=0 ctb=99 tag=6 hlen=3 plen=525
:public key packet:
        version 4, algo 1, created 1599555219, expires 0
        pkey[0]: [4096 bits]
        pkey[1]: [17 bits]
        keyid: 3587A1BDE853CCF2
# off=528 ctb=b4 tag=13 hlen=2 plen=52
:user ID packet: "ahelpme example (ahelpme example) <info@ahelpme.com>"
# off=582 ctb=89 tag=2 hlen=3 plen=596
:signature packet: algo 1, keyid 3587A1BDE853CCF2
        version 4, created 1599555219, md5len 0, sigclass 0x13
        digest algo 8, begin of digest 40 ae
        hashed subpkt 33 len 21 (issuer fpr v4 A24D62FBD20EB1B488D9301A3587A1BDE853CCF2)
        hashed subpkt 2 len 4 (sig created 2020-09-08)
        hashed subpkt 27 len 1 (key flags: 03)
        hashed subpkt 9 len 4 (key expires after 30y0d0h0m)
        hashed subpkt 11 len 4 (pref-sym-algos: 9 8 7 2)
        hashed subpkt 21 len 5 (pref-hash-algos: 10 9 8 11 2)
        hashed subpkt 22 len 3 (pref-zip-algos: 2 3 1)
        hashed subpkt 30 len 1 (features: 01)
        hashed subpkt 23 len 1 (keyserver preferences: 80)
        subpkt 16 len 8 (issuer key ID 3587A1BDE853CCF2)
        data: [4095 bits]
# off=1181 ctb=b9 tag=14 hlen=3 plen=525
:public sub key packet:
        version 4, algo 1, created 1599555219, expires 0
        pkey[0]: [4096 bits]
        pkey[1]: [17 bits]
        keyid: C0D8C4EFE00E6395
# off=1709 ctb=89 tag=2 hlen=3 plen=572
:signature packet: algo 1, keyid 3587A1BDE853CCF2
        version 4, created 1599555219, md5len 0, sigclass 0x18
        digest algo 8, begin of digest c6 77
        hashed subpkt 33 len 21 (issuer fpr v4 A24D62FBD20EB1B488D9301A3587A1BDE853CCF2)
        hashed subpkt 2 len 4 (sig created 2020-09-08)
        hashed subpkt 27 len 1 (key flags: 0C)
        hashed subpkt 9 len 4 (key expires after 30y0d0h0m)
        subpkt 16 len 8 (issuer key ID 3587A1BDE853CCF2)
        data: [4096 bits]

Unencrypted private key

A file with exported and unencrypted private key.

gpg --list-packets <./ahelpme.com.gpg.key 
# off=0 ctb=95 tag=5 hlen=3 plen=1816
:secret key packet:
        version 4, algo 1, created 1599555219, expires 0
        pkey[0]: [4096 bits]
        pkey[1]: [17 bits]
        skey[2]: [4092 bits]
        skey[3]: [2048 bits]
        skey[4]: [2048 bits]
        skey[5]: [2047 bits]
        checksum: 7bc9
        keyid: 3587A1BDE853CCF2
# off=1819 ctb=b4 tag=13 hlen=2 plen=52
:user ID packet: "ahelpme example (ahelpme example) <info@ahelpme.com>"
# off=1873 ctb=89 tag=2 hlen=3 plen=596
:signature packet: algo 1, keyid 3587A1BDE853CCF2
        version 4, created 1599555219, md5len 0, sigclass 0x13
        digest algo 8, begin of digest 40 ae
        hashed subpkt 33 len 21 (issuer fpr v4 A24D62FBD20EB1B488D9301A3587A1BDE853CCF2)
        hashed subpkt 2 len 4 (sig created 2020-09-08)
        hashed subpkt 27 len 1 (key flags: 03)
        hashed subpkt 9 len 4 (key expires after 30y0d0h0m)
        hashed subpkt 11 len 4 (pref-sym-algos: 9 8 7 2)
        hashed subpkt 21 len 5 (pref-hash-algos: 10 9 8 11 2)
        hashed subpkt 22 len 3 (pref-zip-algos: 2 3 1)
        hashed subpkt 30 len 1 (features: 01)
        hashed subpkt 23 len 1 (keyserver preferences: 80)
        subpkt 16 len 8 (issuer key ID 3587A1BDE853CCF2)
        data: [4095 bits]
# off=2472 ctb=9d tag=7 hlen=3 plen=1816
:secret sub key packet:
        version 4, algo 1, created 1599555219, expires 0
        pkey[0]: [4096 bits]
        pkey[1]: [17 bits]
        skey[2]: [4095 bits]
        skey[3]: [2048 bits]
        skey[4]: [2048 bits]
        skey[5]: [2047 bits]
        checksum: 7747
        keyid: C0D8C4EFE00E6395
# off=4291 ctb=89 tag=2 hlen=3 plen=572
:signature packet: algo 1, keyid 3587A1BDE853CCF2
        version 4, created 1599555219, md5len 0, sigclass 0x18
        digest algo 8, begin of digest c6 77
        hashed subpkt 33 len 21 (issuer fpr v4 A24D62FBD20EB1B488D9301A3587A1BDE853CCF2)
        hashed subpkt 2 len 4 (sig created 2020-09-08)
        hashed subpkt 27 len 1 (key flags: 0C)
        hashed subpkt 9 len 4 (key expires after 30y0d0h0m)
        subpkt 16 len 8 (issuer key ID 3587A1BDE853CCF2)
        data: [4096 bits]

Encrypted private key

A file with exported and encrypted private key.

gpg --list-packets <./ahelpme.com.gpg.key.enc
# off=0 ctb=95 tag=5 hlen=3 plen=1862
:secret key packet:
        version 4, algo 1, created 1599556006, expires 0
        pkey[0]: [4096 bits]
        pkey[1]: [17 bits]
        iter+salt S2K, algo: 7, SHA1 protection, hash: 2, salt: 9B520B84D33BA076
        protect count: 29360128 (236)
        protect IV:  e6 d5 ed 30 59 3c dd 2f b8 72 67 ee bd 97 8c 06
        skey[2]: [v4 protected]
        keyid: 1EBB5CBF6F46BE27
# off=1865 ctb=b4 tag=13 hlen=2 plen=73
:user ID packet: "encrypted ahelpme example (encrypted ahelpme example) <info2@ahelpme.com>"
# off=1940 ctb=89 tag=2 hlen=3 plen=596
:signature packet: algo 1, keyid 1EBB5CBF6F46BE27
        version 4, created 1599556006, md5len 0, sigclass 0x13
        digest algo 8, begin of digest 8d 4d
        hashed subpkt 33 len 21 (issuer fpr v4 6274B493CD4DC7344D3DDFCC1EBB5CBF6F46BE27)
        hashed subpkt 2 len 4 (sig created 2020-09-08)
        hashed subpkt 27 len 1 (key flags: 03)
        hashed subpkt 9 len 4 (key expires after 50y0d0h0m)
        hashed subpkt 11 len 4 (pref-sym-algos: 9 8 7 2)
        hashed subpkt 21 len 5 (pref-hash-algos: 10 9 8 11 2)
        hashed subpkt 22 len 3 (pref-zip-algos: 2 3 1)
        hashed subpkt 30 len 1 (features: 01)
        hashed subpkt 23 len 1 (keyserver preferences: 80)
        subpkt 16 len 8 (issuer key ID 1EBB5CBF6F46BE27)
        data: [4095 bits]
# off=2539 ctb=9d tag=7 hlen=3 plen=1862
:secret sub key packet:
        version 4, algo 1, created 1599556006, expires 0
        pkey[0]: [4096 bits]
        pkey[1]: [17 bits]
        iter+salt S2K, algo: 7, SHA1 protection, hash: 2, salt: D2D140F97AE25848
        protect count: 29360128 (236)
        protect IV:  f9 13 9d d8 e6 ff 6f 50 f7 2a f7 13 8d 35 1a 14
        skey[2]: [v4 protected]
        keyid: 361220833AFD4BF5
# off=4404 ctb=89 tag=2 hlen=3 plen=572
:signature packet: algo 1, keyid 1EBB5CBF6F46BE27
        version 4, created 1599556006, md5len 0, sigclass 0x18
        digest algo 8, begin of digest 97 f1
        hashed subpkt 33 len 21 (issuer fpr v4 6274B493CD4DC7344D3DDFCC1EBB5CBF6F46BE27)
        hashed subpkt 2 len 4 (sig created 2020-09-08)
        hashed subpkt 27 len 1 (key flags: 0C)
        hashed subpkt 9 len 4 (key expires after 50y0d0h0m)
        subpkt 16 len 8 (issuer key ID 1EBB5CBF6F46BE27)
        data: [4094 bits]

Leave a Reply

Your email address will not be published.