Hi,

I have a string which has the certificate in PEM(Base64) format. I want to
convert it to DER format(unsigned char). How can I do it?

I wrote the following code:
    BIO *certBio = BIO_new(BIO_s_mem());
    int len = BIO_puts(certBio,value.c_str());
    if (len < 1) {
        BIO_free(certBio);
        return ERROR;
    }
    BIO *bp = certBio;
    X509 *x = PEM_read_bio_X509(bp,NULL,0,NULL);
    if (NULL == x) {
        BIO_free(certBio);
        return ERROR;
    }
    unsigned char *certUc = (unsigned char *) malloc (4 * 1024);
    unsigned char *out = certUc;
    len = i2d_X509(x,&out);
    if (len < 1) {
        BIO_free(certBio);
        X509_free(x);
        free(certUc);
        return ERROR;
    }

This code is compiled using c++ compiler. 'value' is a String which has the
certificate in base64 encoded format.

This code is failing. Am getting 'x' always null. Can anyone pls help me.

I want a DER encoded certificate in unsigned char format from the String.
Can anyone tell me the way.

Thank-you,
Sri

Reply via email to