openssl - X509* certificate serialization and deserialization in C -
i have certificate in 509* format , want serialize char buffer , later desserialize in other recover certificate 509* again.
i doing serialize:
int size_cert = 0; unsigned char* data; bio* bio = bio_new(bio_s_mem()); pem_write_bio_x509(bio,certificate); size_cert = bio_get_mem_data(bio, &data); bio_free(bio);
where data should have certificate data!
to reconstruct x509* certificate data buffer doing this:
bio* bio; x509* cert; bio = bio_new(bio_s_mem()); bio_puts(bio, data); cert = pem_read_bio_x509(bio, null, null, null);
where cert should certificate. not working properly, can 1 give me example this?
i have done below code,
1 load certificate bio using bio_read_filename
2 convert x509 using pem_read_bio_x509_aux
3 convert unsigned char* using i2d_x509
4 reconstruct x509 unsigned char* using d2i_x509
int main() { x509 *x509,*x509ser; bio *certbio = bio_new(bio_s_file()); char * path = "e:\\share\tempcert.pem"; // certificate path int len; unsigned char *buf; buf = null; bio_read_filename(certbio, path); // reading certificate bio x509 = pem_read_bio_x509_aux(certbio, null, 0, null); //converting x509 len = i2d_x509(x509, &buf); // converting unsigned char* x509ser = d2i_x509(null, &buf, len); // converting x509 unsigned char* bio_free_all(certbio); return 0; }
Comments
Post a Comment