使用 openssl 将 .pfx 文件拆分为 .crt 和 .key

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

我正在尝试为我的 API 调用实施客户端身份验证。为了测试这一点,我正在使用 Postman。将 .pfx 客户端证书添加到 Postman 并调用 API 端点时,我得到:

Error: BAD_PKCS12_DATA

经过一番挖掘,我发现了将 .pfx 文件拆分为 .crt 和 .key 的提示。所以我阅读了 openssl 文档并尝试了以下操作:

openssl pkcs12 -in [yourfile.pfx] -nocerts -out [drlive.key]
openssl pkcs12 -in [yourfile.pfx] -clcerts -nokeys -out [drlive.crt]

但是运行这些命令会抛出一个错误:

8000:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:../openss-1.1.1s/crypto/asn1/tasn_dec.c:1149:
8000:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 errr:../openssl-1.1.1s/crypto/asn1/tasn_dec.c:309:Type=PKCS12

有人知道问题出在哪里吗? 顺便说一句:我使用以下方法从 Azure Key Vault 中导出了 .pfx 文件:

az keyvault secret download --file <certname>.pfx --vault-name <keyvaultname> --name <certname>

效果很好。

为了缩小问题范围,我使用以下方法直接从密钥库下载了 .crt 和 .key 文件:

az keyvault certificate download --vault-name <keyvaultname> -n <certname> -f <certname>.crt -e DER
az keyvault secret download --vault-name <keyvaultname> -n <certname> -f <certname>.key

但是当我使用通过 Azure CLI 下载的 .crt 和 .key 文件时,我在 Postman 中收到另一个错误:

Error: error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE

这就是为什么我想测试通过 openssl 将 .pfx 拆分为 .crt 和 .key 的原因。

有人知道为什么提取失败或我做错了什么吗?

authentication openssl postman certificate client
© www.soinside.com 2019 - 2024. All rights reserved.