将 pfx 格式转换为 p12

发布于 2024-11-25 20:18:11 字数 118 浏览 3 评论 0原文

我需要将 .pfx 格式证书(从 Windows MMC)导出到 .p12 以在另一个应用程序中使用。我找不到办法做到这一点。

任何人都可以建议一个方法吗?

I need to export a .pfx format certificate (from Windows MMC) to .p12 to use in another application. I cant find a way to do this.

Can anyone suggest a method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

咋地 2024-12-02 20:18:11

.p12.pfx 都是 PKCS #12 文件。我错过了什么吗?

您是否尝试过将导出的 .pfx 文件重命名为具有 .p12 扩展名?

.p12 and .pfx are both PKCS #12 files. Am I missing something?

Have you tried renaming the exported .pfx file to have a .p12 extension?

沙与沫 2024-12-02 20:18:11

我在使用 openconnect 处理 .pfx 文件时遇到了问题。重命名并没有解决问题。我使用 keytool 将其转换为 .p12 并且它有效。

keytool -importkeystore -destkeystore new.p12 -deststoretype pkcs12 -srckeystore original.pfx

就我而言,新文件 (new.p12) 的密码必须与 .pfx 文件的密码相同。

I had trouble with a .pfx file with openconnect. Renaming didn't solve the problem. I used keytool to convert it to .p12 and it worked.

keytool -importkeystore -destkeystore new.p12 -deststoretype pkcs12 -srckeystore original.pfx

In my case the password for the new file (new.p12) had to be the same as the password for the .pfx file.

岁月流歌 2024-12-02 20:18:11

如果您正在寻找带有 UI 的快速手动流程。我总是使用 Mozilla Firefox 从 PFX 转换为 P12。首先将证书导入 Firefox 浏览器(选项 > 隐私和安全 > 查看证书... > 导入...)。安装后,通过从证书管理器中选择证书名称来执行导出以创建 P12 文件,然后单击备份...并输入文件名,然后输入密码。

If you are looking for a quick and manual process with UI. I always use Mozilla Firefox to convert from PFX to P12. First import the certificate into the Firefox browser (Options > Privacy & Security > View Certificates... > Import...). Once installed, perform the export to create the P12 file by choosing the certificate name from the Certificate Manager and then click Backup... and enter the file name and then enter the password.

燕归巢 2024-12-02 20:18:11

这更多的是jglouie回应的延续。

如果您使用 openssl 将 PKCS#12 证书转换为公钥/私钥 PEM 密钥,则无需重命名该文件。假设该文件名为 cert.pfx,以下三个命令将创建一个公共 pem 密钥和一个加密的私有 pem 密钥:

openssl pkcs12 -in cert.pfx     -out cert.pem     -nodes -nokeys
openssl pkcs12 -in cert.pfx     -out cert_key.pem -nodes -nocerts
openssl rsa    -in cert_key.pem -out cert_key.pem -des3

前两个命令可能会提示输入导入密码。这将是随 PKCS#12 文件提供的密码。

第三条命令将让您指定证书的加密密码。这是您在使用证书时将输入的内容。

This is more of a continuation of jglouie's response.

If you are using openssl to convert the PKCS#12 certificate to public/private PEM keys, there is no need to rename the file. Assuming the file is called cert.pfx, the following three commands will create a public pem key and an encrypted private pem key:

openssl pkcs12 -in cert.pfx     -out cert.pem     -nodes -nokeys
openssl pkcs12 -in cert.pfx     -out cert_key.pem -nodes -nocerts
openssl rsa    -in cert_key.pem -out cert_key.pem -des3

The first two commands may prompt for an import password. This will be a password that was provided with the PKCS#12 file.

The third command will let you specify the encryption passphrase for the certificate. This is what you will enter when using the certificate.

月朦胧 2024-12-02 20:18:11

首先我们有certificate.PFX文件

第1步:(提取私钥)

openssl pkcs12 -in certificate.pfx -nocerts -out private.key -passin pass:123123 -passout pass:123123

第2步:(创建P12文件)

openssl pkcs12 -export -out ewallet.p12 -inkey private.key -in certificate.cer -passin pass:123123 -passout pass:123123

first We Have certificate.PFX file

Step1: (Extract Private Key)

openssl pkcs12 -in certificate.pfx -nocerts -out private.key -passin pass:123123 -passout pass:123123

Step2: (Create P12 file)

openssl pkcs12 -export -out ewallet.p12 -inkey private.key -in certificate.cer -passin pass:123123 -passout pass:123123
囚我心虐我身 2024-12-02 20:18:11

就我而言,我想导入从 Entrust 导出的 .pfx 并将其导入到 gpgsm 中。 gpgsm 不喜欢 PFX:

$ gpgsm --import name.pfx
gpgsm: directory '/home/me/.gnupg' created
gpgsm: keybox '/home/me/.gnupg/pubring.kbx' created
gpgsm: data error at "pkcs5PBES2-params", offset 134
gpgsm: error at "bag-sequence", offset 49
gpgsm: error parsing or decrypting the PKCS#12 file
gpgsm: total number processed: 0

Paul Chan 的上述答案有效(使用 Firefox),但我想要命令行解决方案。

受到其他答案的启发,我只是尝试使用 openssl pcks12 进行往返,并且它有效:

# Convert pfx to pem
$ openssl pkcs12 -in name.pfx -out name.pem
# Convert pem to p12
openssl pkcs12 -export -in name.pem -out name.p12
$ gpgsm --import name.p12
gpgsm: 2456 bytes of RC2 encrypted text
# ...
gpgsm: total number processed: 3
gpgsm:               imported: 2
gpgsm:       secret keys read: 1
gpgsm:   secret keys imported: 1

In my case, I wanted to import a .pfx exported from Entrust and import it into gpgsm. gpgsm did not like that PFX:

$ gpgsm --import name.pfx
gpgsm: directory '/home/me/.gnupg' created
gpgsm: keybox '/home/me/.gnupg/pubring.kbx' created
gpgsm: data error at "pkcs5PBES2-params", offset 134
gpgsm: error at "bag-sequence", offset 49
gpgsm: error parsing or decrypting the PKCS#12 file
gpgsm: total number processed: 0

Paul Chan's answer above worked (using Firefox), but I wanted a command line solution.

Inspired by the other answers, I simply tried roundtripping it using openssl pcks12, and it worked:

# Convert pfx to pem
$ openssl pkcs12 -in name.pfx -out name.pem
# Convert pem to p12
openssl pkcs12 -export -in name.pem -out name.p12
$ gpgsm --import name.p12
gpgsm: 2456 bytes of RC2 encrypted text
# ...
gpgsm: total number processed: 3
gpgsm:               imported: 2
gpgsm:       secret keys read: 1
gpgsm:   secret keys imported: 1
℡寂寞咖啡 2024-12-02 20:18:11

看来遗留加密算法已在 openssl 中删除,但仍在 gpsm 中使用。这意味着您必须在使用 openssl 转换密钥时显式重新启用它们:

openssl pkcs12 -in input.pfx -out output.pem
openssl pkcs12 -export -in output.pem -out output.p12 -legacy

It seems that legacy encryption algorithms have been dropped in openssl which are still used in gpsm. This means that you have to explicitly re-enable them while converting the keys with openssl:

openssl pkcs12 -in input.pfx -out output.pem
openssl pkcs12 -export -in output.pem -out output.p12 -legacy
盛夏尉蓝 2024-12-02 20:18:11

运行此命令将 .cert 文件更改为 .p12

openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt 

其中 server.key 是服务器密钥,server.cert 是 CA 颁发的证书或自签名证书文件。

Run this command to change .cert file to .p12:

openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt 

Where server.key is the server key and server.cert is a CA issue cert or a self sign cert file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文