[openssl-users] get type of PEM data
Richard Levitte
levitte at openssl.org
Wed Mar 28 20:34:26 UTC 2018
In message <c4b8313e-a8ec-0bee-dae2-147cee6214d5 at jordan.maileater.net> on Wed, 28 Mar 2018 08:02:37 -0700, Jordan Brown <openssl at jordan.maileater.net> said:
openssl> I'm finding that it would be helpful to have a function that
openssl> would, given PEM data (in memory or in a file) return an
openssl> indication of what kind of object it represents: a
openssl> certificate, a private key, et cetera. The ideal function
openssl> would basically tell me which PEM_read_bio_foobar function I
openssl> would use to read the PEM data (and thus what C type it
openssl> represents). It would lump all private key formats into one
openssl> type, since PEM_read_PrivateKey would work on all of them and
openssl> return an EVP_PKEY.
openssl>
openssl> Does such a function already exist? Any thoughts?
PEM_read and PEM_read_bio should do what you want. You need to
provide three buffers, |name|, |header| and |data|. |name| will
contain the name from the -----BEGIN line, that string describes the
type of data you have in |data|.
I suggest you read the manual on these functions, there are a few
things you need to do to decode something that's encrypted, for
example.
Cheers,
Richard
More information about the openssl-users
mailing list