gpt4 book ai didi

c++ - 在 C++ 中将 PEM 转换为 DER

转载 作者:搜寻专家 更新时间:2023-10-31 02:12:50 25 4
gpt4 key购买 nike

我有一个 PEM 格式的证书,我想使用 C++ 中的 OpenSLL 函数将其转换为 DER 格式。

我该怎么做?

谢谢。

最佳答案

你可以这样做——

#include <stdio.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/err.h>

void convert(char* cert_filestr,char* certificateFile)
{
X509* x509 = NULL;
FILE* fd = NULL,*fl = NULL;

fl = fopen(cert_filestr,"rb");
if(fl)
{
fd = fopen(certificateFile,"w+");
if(fd)
{
x509 = PEM_read_X509(fl,&x509,NULL,NULL);
if(x509)
{
i2d_X509_fp(fd, x509);
}
else
{
printf("failed to parse to X509 from fl");
}
fclose(fd);
}
else
{
printf("can't open fd");
}
fclose(fl);
}
else
{
printf("can't open f");
}
}


int main()
{
convert("abc.pem","axc.der");
return 0;
}

关于c++ - 在 C++ 中将 PEM 转换为 DER,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42199503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com