Can anyone show me how to convert .crt files to .pem files using the openssl API? I tried it like this:
FILE *fl = fopen(cert_filestr, "r");
fseek(fl, 0, SEEK_END);
long len = ftell(fl);
char *ret = malloc(len);
fseek(fl, 0, SEEK_SET);
fread(ret, 1, len, fl);
fclose(fl);
BIO* input = BIO_new_mem_buf((void*)ret, sizeof(ret));
x509 = d2i_X509_bio(input, NULL);
FILE* fd = fopen(certificateFile, "w+");
BIO* output = BIO_new_fp(fd, BIO_NOCLOSE);
X509_print_ex(output, x509, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
fclose(fd);
But that doesn't work, x509 is always NULL.
sizeofon a pointer gives you the size of the pointer and not what it points to.void*, all pointers can implicitly be casted to (and from)void*.len, it's the size you need to pass toBIO_new_mem_buf.