9

I normally wouldn't ask but I can't find the answer on SO or google.

I'm using a library that accepts base64 encoded pgp public keys in string format. However, one of the components I need to convert has a key in .asc format. How can I convert it back to binary-pgp or base64-gp.

Sorry if it's really dumb question, I'm new to the pgp toolsets.

Thanks a lot!

Shane

ShaneK
  • 249
  • 1
  • 2
  • 7

2 Answers2

14

Turns out it's really simple:

gpg --dearmor file.asc

Source: https://lists.gnupg.org/pipermail/gnupg-devel/2011-October/026253.html

Community
  • 1
  • 1
ShaneK
  • 249
  • 1
  • 2
  • 7
  • Note quite: it's either `gpg --dearmor file.asc` and the de-armored output will be in `file.asc.gpg` or `gpg --dearmor < file.asc > file.gpg` which reads and writes from/to stdin. – ckujau Jun 12 '22 at 23:44
  • @ckujau careful with the last one: if gpg fail (or command doesn't exist), `file.gpg` will still be created, with a size of 0. – 4wk_ Jul 19 '22 at 09:33
7

If you want to avoid a final filename of .asc.gpg, you can use the -o option of gpg, like so:

gpg -o foobar.gpg --dearmor foobar.asc

(I don't recommend using gpg --dearmor < file.asc > file.gpg because if gpg fail or does not exist, file.gpg will still be created (empty file), which lead to unwanted side effect when working with automation).

4wk_
  • 2,458
  • 3
  • 34
  • 46