Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing SW that uses opessl library for verifying DSA signatures. I have public keys from senders in gpg format. How can I convert those into .pem so that openssl can read them?

I found this from another thread:

gpgsm -o secret-key.p12 --export-secret-key-p12 0xXXXXXXXX 

To do the export I need to have the keys in gpgsm keyring don't I? I just can't figure out how to import my keys into the keyring gpgsm is using. I end up with errors:

gpgsm --import public.asc
gpgsm: total number processed: 0
gpgsm: error importing certificate: End of file

Can gpgsm somehow use gpg:s keyring and do the export from there?

share|improve this question

Your export command is correct but as you suppose, the gpgsm's keyring is empty. You can check that with:

gpgsm --list-keys

The output will be nothing.

For your last question: Nope. gpg and gpgsm use different databases. More info is here. You have to create or obtain an OpenSSL key/cert pair and import it (in PKCS#12 format) into gpgsm keyring (usually ~/.gnupg/pubring.kbx) so the import command must be:

gpgsm --import mycert.p12

You can export the keys from one system, convert them and import to another one, but the so-called conversion just supplies the metainfo (in most cases) and a brand new cert/key is being created with that metainfo. You can look here for conversion examples.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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