Debian – How to generate an .asc file from pgp public key

debianencryptiongpg

From what little I know, in openpgp you have a private key which you keep locked or hidden somewhere and a public key which you can freely share with anybody.

Now I have seen many people attaching .asc file. If I click on that, it reveals the other person's public key.

Is having an .asc file nothing but using the putting your public key and then renaming it as something like signature.asc or is something else involved as well ? The .asc file seems to be an archive file (like a .rar or zip file)

$ cat shirish-public-key.txt
-----BEGIN PGP SIGNATURE-----
publickeystring$
-----END PGP SIGNATURE-----

How can I make/transform it into an .asc file ?

I could just do –

$ mv shirish-public-key.txt shirish.asc

but I don't know if that is the right thing to do or not.

Update – I tried but it doesn't work 🙁

$ gpg --armor export shirish-public-key.txt > pubkey.asc
gpg: WARNING: no command supplied.  Trying to guess what you mean ...
usage: gpg [options] [filename]

Update 2 – Still it doesn't work –

$ gpg --armor --export shirish-public-key.txt > pubkey.asc 
gpg: WARNING: nothing exported

seems it can't figure out that the public key is in a text file .

Update 3 –

This is what the contents of the file look like

See http://paste.debian.net/1022979/

But if I run –

 $ gpg --import shirish-public-key.txt 
    gpg: invalid radix64 character 3A skipped
    gpg: invalid radix64 character 2E skipped
    gpg: invalid radix64 character 2E skipped
    gpg: invalid radix64 character 2E skipped
    gpg: invalid radix64 character 3A skipped
    gpg: invalid radix64 character 3A skipped
    gpg: invalid radix64 character 2E skipped
    gpg: CRC error; 1E6A49 - B36DCC
    gpg: [don't know]: invalid packet (ctb=55)
    gpg: read_block: read error: Invalid packet
    gpg: import from 'shirish-public-key.txt' failed: Invalid keyring
    gpg: Total number processed: 0

Seems something is wrong somewhere.

FWIW gpg is version 2.2.5 from Debian testing (am running testing with all updates)

$ gpg --version
gpg (GnuPG) 2.2.5
libgcrypt 1.8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: /home/shirish/.gnupg
Supported algorithms:
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

Best Answer

Usually, a .asc file is an ASCII-armored representation of key material (or a signature). Your shirish-public-key.txt looks like it’s just that, so if you’re sure it contains the right information you could simply rename it, as you suggest. (I doubt it contains your public key though — that should start with -----BEGIN PGP PUBLIC KEY BLOCK-----.) If a file contains “binary” data (which I’m guessing is what you mean when you say it looks like an archive), it’s not an ASCII file and wouldn’t usually be named with a .asc extension.

To export your key in this format, from your keyring rather than an existing file (thus ensuring it contains the correct data), run

gpg --armor --export YOUR_FINGERPRINT > pubkey.asc

To make things easier, files are often named by their key id; in my case:

gpg --armor --export "79D9 C58C 50D6 B5AA 65D5  30C1 7597 78A9 A36B 494F" > 0x759778A9A36B494F.asc

There are various options you can use to tweak the exported data; for example, --export-options export-minimal will strip most signatures from the key, greatly reducing its size (but also its utility for people who care about the web of trust).

Related Question