以编程方式将 .PFX 转换为 .PEM? [英] Converting .PFX to .PEM programmatically?

查看:26
本文介绍了以编程方式将 .PFX 转换为 .PEM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式从 MS 证书存储中提取证书及其私钥,并以某种方式将它们转换为 .PEM 格式.我不想在命令行中使用 OpenSSL,因为我想将所有内容都保存在内存中,避免使用文件.

I need to programmatically extract certificates and their private keys from a MS certificate store, and get them to the .PEM format somehow. I don't want to use OpenSSL at the command line, as I would like to keep everything in memory, avoiding files.

我可以使用 PFXExportCertStoreEx() 将它们从 Windows 导出到 PFX 格式的 blob.我通过将其写入文件并使用 OpenSSL 将其转换为 .PEM 来测试它.生成的 .PEM 文件工作正常.所以剩下的问题是让它们在内存中变成 .PEM 格式.

I can export them from Windows to a PFX-format blob using PFXExportCertStoreEx(). I tested that by writing it to a file and converting it to .PEM with OpenSSL. The resulting .PEM file works fine. So the remaining problem is to get them to the .PEM format in memory.

我们集成了一个需要 .PEM 的不同 SSL 库.(这不是 OpenSSL ...)所以我想在不将 OpenSSL 源代码包含到我们的 C++ 项目中的情况下完成此操作.有什么想法吗?

We've integrated a different SSL library that wants .PEM. (It's not OpenSSL...) So I'd like to accomplish this without also including OpenSSL source into our C++ project. Any ideas?

推荐答案

静态链接到 OpenSSL .lib 文件怎么样?

How about statically linking to OpenSSL .lib files?

我已经调整了一些使用 OpenSSL 的示例来执行此操作,您可以在此处找到将 pfx 转换为 pem 的 c++ 代码:https://github.com/michaelmotes/PKCS12toPEM

I have adapted some examples using OpenSSL to do this, you can find c++ code to convert pfx to pem here: https://github.com/michaelmotes/PKCS12toPEM

此文件包含使用 OpenSSL 将 PFX 转换为 PEM 的 VB.NET 互操作代码:

And this file contains VB.NET Interop code to convert PFX to PEM using OpenSSL:

https://github.com/michaelmotes/libCurlVB.NET-native/blob/master/LibCurlDecl.vb

这篇关于以编程方式将 .PFX 转换为 .PEM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆