JamieH
JamieH

Reputation: 4849

Open SSL extract certificate from X509 structure into char array

I am using OpenSSL to construct my own self signed certificate which I have in an X509 structure. I wan't to extract the certificate data out of the X509 structure into a char array.

I am aware of the following macro:

PEM_Write_X509(file *, certificate *)

This will output to a file something like:

-----BEGIN CERTIFICATE------
DATAHERE
-----END CERTIFICATE-----

What I really want is just the "DATAHERE" part directly into a char array. There are a baffling number of macros for doing various things, but I haven't stumbled across one that does what I'm after. Is there anything suitable that I haven't found?

Upvotes: 1

Views: 1696

Answers (2)

What you presented is a PEM-encoded representation of the certificate (which by itself is a DER data).

In your case you just strip this text and you have base64-encoded DER data of the certificate.

Upvotes: 0

Drona
Drona

Reputation: 7234

BEGIN and END sections are boundaries for the PEM text. This is standard convention. I believe, removing these sections will make the certificate unusable.

Upvotes: 2

Related Questions