1. Equivalent to: openssl x509 -in "cer_path" -inform DER -out "save_path" -outform PEM
2. The code is as follows: cerFilePath is cer file; cer file after the file request csr obtained.
bool MakePemSSL(const char* cerFilePath, const char* savePemFilePath) {
int ret = 0;
X509 *x509 = NULL;
FILE *cerFile = NULL, *pemFile = NULL;
cerFile = fopen(cerFilePath, "rb");
if (cerFile == NULL) {
fprintf(stderr, "MakeLocalPemSSL fopen cerFilePath err \n");
goto free_all;
}
pemFile = fopen(savePemFilePath, "w+");
if (pemFile == NULL) {
fprintf(stderr, "MakeLocalPemSSL fopen savePemFilePath err \n");
goto free_all;
}
x509 = d2i_X509_fp(cerFile, NULL);
if (x509 == NULL) {
fprintf(stderr, "MakeLocalPemSSL failed to parse to X509 from cerFile \n");
goto free_all;
}
ret = PEM_write_X509(pemFile, x509);
if (ret != 1) {
fprintf(stderr, "MakeLocalPemSSL failed to PEM_write_X509 \n");
goto free_all;
}
free_all:
if (cerFile) fclose(cerFile);
if (pemFile) fclose(pemFile);
return (ret == 1);
}
the above.
"One of the C ++ OpenSSL: compile and use"
, "C ++ OpenSSL II: generate RSA File"
"Three C ++ OpenSSL's: Generating a CSR file"
, "C ++ OpenSSL Four: CER converted to PEM"
"C ++ OpenSSL five: generate P12 file "
Reproduced in: https: //www.cnblogs.com/chevin/p/11041763.html