使用 openssl 向无密码 PFX 添加密码

问题描述 投票:0回答:1

从 Azure Key Vault 导出 PFX 时,导出的 PFX 不带密码(或者可能带有空密码)。

我需要使用 openssl 向 PFX 文件添加密码。通过阅读各种网站,我需要提取密钥和 crt 文件,然后将它们重新组合成一个文件,但这次需要密码。但是,每次尝试读取无密码 PFX 文件都会导致错误。

140462554078016:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto/asn1/tasn_dec.c:1149:
140462554078016:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:309:Type=PKCS12

我尝试了以下变体并包含了错误:

X:\Temp>openssl pkcs12 -in 443.pfx -nocerts -out 443.key
F8CB0000:error:068000A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto\asn1\tasn_dec.c:1188:
F8CB0000:error:0688010A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:crypto\asn1\tasn_dec.c:349:Type=PKCS12

X:\Temp>openssl pkcs12 -in 443.pfx -out 443.key -passout pass: -passin pass:""
58860000:error:068000A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto\asn1\tasn_dec.c:1188:
58860000:error:0688010A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:crypto\asn1\tasn_dec.c:349:Type=PKCS12

X:\Temp>openssl pkcs12 -in 443.pfx -out 443.key -passin pass:""
FCAA0000:error:068000A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto\asn1\tasn_dec.c:1188:
FCAA0000:error:0688010A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:crypto\asn1\tasn_dec.c:349:Type=PKCS12

X:\Temp>openssl pkcs12 -in 443.pfx -out 443.key -passin pass:
40A90000:error:068000A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto\asn1\tasn_dec.c:1188:
40A90000:error:0688010A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:crypto\asn1\tasn_dec.c:349:Type=PKCS12

X:\Temp>openssl pkcs12 -in 443.pfx -out 443.key -passin
pkcs12: Option -passin needs a value
pkcs12: Use -help for summary.

X:\Temp>openssl pkcs12 -in 443.pfx -out 443.key -passin pass:abc
58B50000:error:068000A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto\asn1\tasn_dec.c:1188:
58B50000:error:0688010A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:crypto\asn1\tasn_dec.c:349:Type=PKCS12

X:\Temp>openssl pkcs12 -in 443.pfx -out 443.key -nodes
80940000:error:068000A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto\asn1\tasn_dec.c:1188:
80940000:error:0688010A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:crypto\asn1\tasn_dec.c:349:Type=PKCS12

PFX 本身始于

MIINhgIBAzCCDUIGCSqGSIb3DQEHAaC

并以

结尾
rMdLz4AGINAgIH0A==

我可以成功将 PFX 导入 Windows(在密码提示下,我只需按回车键即可导入 PFX)。

用于提取密钥和 crt 文件的 openssl 命令有哪些?

ssl openssl pem
1个回答
0
投票

一般情况下,PFX 文件生成时没有密码。导入并要求输入密码时,通常可以将其留空。有些系统坚持要求输入密码。

因此我们建议使用密码重新生成 PFX 文件。这可以使用 OpenSSL 来完成

首先将PFX文件转换为PEM。

openssl pkcs12 -in cert.pfx -out cert.pem -nodes

然后将 PEM 文件转换回 PFX 并指定密码

openssl pkcs12 -export -out cert.pfx -in cert.pem 输入导出密码: 验证 - 输入导出密码:

© www.soinside.com 2019 - 2024. All rights reserved.