1.等同于使用: openssl  x509 -in "cer_path" -inform DER -out "save_path" -outform PEM

2.代码如下:cerFilePath是cer文件;cer文件是csr文件请求后获得。

bool MakePemSSL(const char* cerFilePath, const char* savePemFilePath) {
int ret = ;
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 != ) {
fprintf(stderr, "MakeLocalPemSSL failed to PEM_write_X509 \n");
goto free_all;
} free_all:
if (cerFile) fclose(cerFile);
if (pemFile) fclose(pemFile); return (ret == );
}

以上。

《C++ OpenSSL 之一:编译和使用》
《C++ OpenSSL 之二:生成RSA文件》
《C++ OpenSSL 之三:生成CSR文件》
《C++ OpenSSL 之四:CER转换为PEM》
《C++ OpenSSL 之五:生成P12文件

C++ OpenSSL 之四:CER转换为PEM的更多相关文章

  1. DER、CRT、CER、PEM格式的证书及转换

    一.证书和编码 X.509证书,其核心是根据RFC 5280编码或数字签名的数字文档. 实际上,术语X.509证书通常指的是IETF的PKIX证书和X.509 v3证书标准的CRL 文件,即如RFC ...

  2. pfx,cer转pem,并对通过pem文件进行签名与验签

    因为PHP无法读取.pfx文件,所以可以先转换为.pem文件然后在读取里面的数据,可以读取.cer文件,为了两方面统一,就都换成.pem然后再进行加签和验签. sign.php <?php de ...

  3. Cer Crt Pem Pfx 证书格式转换

    1.从pfx格式的证书提取出密钥和证书set OPENSSL_CONF=openssl.cnfopenssl pkcs12 -in my.pfx -nodes -out server.pemopens ...

  4. APNS .p12文件转换为 .pem文件

    1:先用mac的钥匙串工具,把APN的推送证书转换为 .p12文件: 2:在mac的终端下 把.p12文件转换为 .pem文件 openssl pkcs12 -in apns-dev-cert.p12 ...

  5. [OPENSSL下载][证书] OPENSSL将PFX证书转换为PEM格式

    OpenSSL Convert PFX Convert PFX to PEM openssl pkcs12 -in certificate.pfx -out certificate.cer -node ...

  6. ssl证书转换cer转pem

    .pem证书转.cer证书 openssl x509 -outform der -in demo.pem -out demo.cer .cer证书转.pem证书 openssl x509 -infor ...

  7. ios 将p12文件转换为pem

    cd 到 文件所在目录 执行以下命令,生成ck.pem文件. openssl pkcs12 -in ck.p12 -out ck.pem -nodes

  8. C++ OpenSSL 之一:编译和使用

    1.官网 https://www.openssl.org/ 当前使用版本为OpenSSL 1.1.1c 2.编译 ①下载后解压,假设解压位置为/home/openssl-1.1.1c ②./confi ...

  9. C++ OpenSSL 之二:生成RSA文件

    1.等同于生成private key: openssl genrsa -out "save_path" 2048 2.代码如下 bool MakeRsaKeySSL(const c ...

随机推荐

  1. python27期day18:模块和包、作业。

    1.模块和包: 我们今天来讲解一下模块和包,模块我们已经知道是什么东西了,我们现在来看看这个包是个什么? 我说的包可不是女同胞一看见就走不动的包,而是程序中一种组织文件的形式. 只要文件夹下含有__i ...

  2. 【Spring IoC】IoC介绍(一)

    IoC(Inversion of Control)的职责:原先由程序员主动通过new实例化对象这个事情,现在交由Spring负责,即由IoC容器负责. Spring 容器是 Spring 框架的核心. ...

  3. LeetCode 112. Path Sum路径总和 (C++)

    题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...

  4. 第五周周二练习:实验 5 Spark SQL 编程初级实践

    1.题目: 源码: import java.util.Properties import org.apache.spark.sql.types._ import org.apache.spark.sq ...

  5. C++面向对象程序设计学习笔记(2)

    C++在非面向对象方面的扩充 C++向下兼容C语言,因此C语言中的语法在C++中依然成立 输入输出 C++添加了标准输入流对象cin和标准输出流对象cout来进行输入输出, 例: #include&l ...

  6. <Stack> 150 71 388

    150. Evaluate Reverse Polish Notation class Solution { public int evalRPN(String[] tokens) { Stack&l ...

  7. 知识点总结 VUE部分

    1.v-show和v-if的区别 v-show 操作的是元素的display属性 v-if 操作的是元素的创建和插入 v-if有更高的开销,而v-show有更高的初始渲染开销,如果需要非常频繁的切换, ...

  8. [探究] [Luogu4550]收集邮票的概率意义

    自认为这道题是一道比较简单的扩展题--?此处采用了和别的题解思路不同的,纯概率意义上的解法. 首先考虑一个简化版问题: 每次随机一个\([1,n]\)的整数,问期望几次能凑出所有数 这东西我写过一个b ...

  9. [LeetCode] 215. Kth Largest Element in an Array 数组中第k大的数字

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  10. Error running 'xxx': Command line is too long. Shorten command line for xxx

    跑单元测试时,报错如下: Error running 'xxx': Command line is too long. Shorten command line for xxx 解决方案: 在项目所在 ...