Is there any OpenSSL function to convert a PKCS7 file to PEM

Is there any openssl api function to convert a PKCS7 file to PEM. I can convert the PKCS12 file to PEM using the PKCS12_parse () function, which returns a key and certificate with a password. There is no similar function for pkcs7.

In my pkcs7 input there is only a binary certificate. I can do the conversion using the command

openssl pkcs7 -inform DER -in input.p7b -printcerts -text

How to do this in a C program? I can read it in a PKCS7 structure like this

 FILE* fp;
 if (!(fp = fopen("ca.p7b", "rb"))) { 
  fprintf(stderr, "Error reading input pkcs7 file\n" ); 
  exit(1); 
 } 
 PKCS7 *p7; 
 p7 = d2i_PKCS7_fp(cafp, NULL);
+3
source share
1 answer

After some searches, I can do this.

if(p7->d.sign->cert != NULL){
    PEM_write_X509(fp, sk_X509_value(p7->d.sign->cert, 0)); 
}

where p7 is a pointer to a pkcs7 struct, and fp is a pointer to a PEM file

+1
source

Source: https://habr.com/ru/post/1727674/


All Articles