Hello OpenSSL,
I'm working on a program that generates pairs of keys and then writes the ASN.1 encoded SubjectPublicKeyInfo (RFC 5280[1]) to a file.
I turned to API `X509_PUBKEY`, and especially `X509_PUBKEY_set`[2], which seems to do the trick by taking an `EVP_PKEY` object that contains the public key:
However, I'm kind of lost when it comes to encoding it to an ASN.1 document.
The X509_PUBKEY structure represents the ASN.1 SubjectPublicKeyInfo structure defined in RFC5280 and used in certificates and certificate requests.
However, I'm kind of lost when it comes to encoding it to an ASN.1 document.
The documentation states the following:
i2d_PUBKEY() encodes an EVP_PKEY structure using SubjectPublicKeyInfo format.
So it seems that I can use `i2d_PUBKEY` with an `EVP_PKEY` directly without having to deal with an intermediate `X509_PUBKEY` object. However, `i2d_X509_PUBKEY` also exists but it doesn't have a dedicated manpage (only the generic manpage[3] about encoding/decoding from/to ASN.1).
My question is: which one should I use?
Regards,
- thomas
[2]: https://www.openssl.org/docs/man3.2/man3/X509_PUBKEY_set.html
[3]: https://www.openssl.org/docs/man3.2/man3/i2d_X509_PUBKEY.html
[3]: https://www.openssl.org/docs/man3.2/man3/i2d_X509_PUBKEY.html