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

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:
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

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).

  • couldn't get it to work, see above. – shirish May 1 '18 at 8:07
  • Note the hyphens before export, they’re necessary... And you can’t export your existing file, you need to give your key id or fingerprint. – Stephen Kitt May 1 '18 at 8:24
  • hi, thank you for the feedback, updated my question again, this time get the gpg warning:nothing exported. – shirish May 1 '18 at 13:52
  • 1
    You’re still not specifying your fingerprint. Your fingerprint is a series of hex digits, similar to that given in my example; it’s not shirish-public-key.txt. – Stephen Kitt May 1 '18 at 14:03
  • 1
    Are you sure it contains your public key? Does gpg --import shirish-public-key.txt work? – Stephen Kitt May 2 '18 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.