0

Can I convert a PGP key to X.509, using OpenSSL or GNUPG?

Aren't these only container/wrapper formats?

1
  • x.509 is a container format for certificates, and PGP keys are specially encoded keys. There not transformable into one another…. Specifically because you need a key container. Not a certificate container. And one of the same type as the PGP key is…. Such as a RSA container. (That can be done….but why would you want that?)
    – LvB
    Commented Mar 7 at 0:18

1 Answer 1

3

Can I convert a PGP key to X.509, using OpenSSL or GNUPG?

The GnuPG software, originally developed for PGP, in recent years also supports SMIME which uses X.509/PKIX, and OpenSSH.

  1. given an RSA private PGP key (which PGP and GnuPG call secret for historical reasons) you can convert it to an SMIME key and export that as PKCS8 X509 and/or PKCS12 (which is a wrapper for both PKCS8 and X509). See
    Create CSR for S/MIME certificate from existing OpenPGP key pair
    Extract OpenPGP secret key material to use as X.509 root CA's key
    https://superuser.com/questions/435321/how-can-i-export-public-keys-in-pem-format-with-gnupg

  2. recent gpg --export-ssh-key exports a PGP public key in the format(s) used by OpenSSH, and OpenSSH (not OpenSSL) can then convert these formats to X.509 SPKI (but not a full certificate) with ssh-keygen -e -m PKCS8 (note this is NOT PKCS8 even though OpenSSH calls it so). See the superuser Q from #1 above and
    https://superuser.com/questions/360507/are-gpg-and-ssh-keys-interchangable

Also, as I noted on those and some similar Qs, you can write Java code for any and all conversions between these key formats using the BouncyCastle libraries, which support the PKCS and X509-based formats used by OpenSSL and the PGP formats -- and in recent years the OpenSSH formats to boot.

Aren't these only container/wrapper formats?

Not at all.

  • SSH protocol defines XDR-based wire formats for transmitting publickeys. OpenSSH, mentioned above, has for decades stored publickeys as a base64 encoding of the wire format(s), and since 6.5 (2014) defines a privatekey file format similarly based on XDR. A variant of the publickey format, with added linebreaks and (minimal) metadata, is standardized as RFC4716, but little used.

  • the XML standards for signature and encryption -- XMLdsig and XMLenc, together XMLsec -- define and use XML-based key formats. These were popular for a while as SOAP, but now survive mostly in SAML, although I believe there are still some EDI applications.

  • the JOSE (Json signing and encryption) standards define Json-based key formats called JWK -- Json Web Key -- used mostly in conjuction with JWT -- Json Web Token(s).

  • the COSE (CBOR signing and encryption) standards, derived from JOSE, define key formats with the same content as JWK but encoded differently.

And I'm sure there are more. Edits welcome.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .