【问题标题】:Extract certificates from PFX file _without_ using OpenSSL_without_ 使用 OpenSSL 从 PFX 文件中提取证书
【发布时间】:2010-10-08 20:30:12
【问题描述】:

我找到了一个answer that uses OpenSSL,但我在 Windows 上,而且手头并不容易。有没有办法(例如使用 CERTUTIL 或 VBScript)查看 .PFX 文件中的证书?

如果我使用“certutil -dump”,它会询问密钥的密码。我不想要密钥,而且证书应该是公开的。

【问题讨论】:

    标签: pfx


    【解决方案1】:

    您可以从pkiclient 使用Get-PfxData

    https://docs.microsoft.com/en-us/powershell/module/pkiclient/get-pfxdata?view=win10-ps

    例子:

    $mypwd = ConvertTo-SecureString -String "localhost" -Force -AsPlainText
    $mypfx = Get-PfxData -FilePath C:\Users\oscar\Desktop\localhost.pfx -Password $mypwd   
    $mypfx
    $mypfx.EndEntityCertificates
    

    如果您有证书并需要 .sst(Microsoft 序列化证书存储)、.cer (CERT) 或 .p7b (PKCS#7) 文件,您可以使用 Export-Certificate from pkiclient (或通过 MMC 导出,无需私钥)。

    https://docs.microsoft.com/en-us/powershell/module/pkiclient/export-certificate?view=win10-ps

    导出 IIS Express 生成的 localhost 证书的示例:

    启动 mmc.exe。

    然后转到:

    文件 -> 添加或删除管理单元 -> 证书 -> 添加 -> 计算机帐户 -> 本地计算机

    展开个人文件夹,您将看到您的本地主机证书。

    双击,转到详细信息并复制证书指纹。

    然后运行命令:

    $cert = (Get-ChildItem -Path cert:\LocalMachine\My\{YourThumbprint})
    Export-Certificate -Cert $cert -FilePath C:\Users\oscar\Desktop\localhost.cer
    

    注意:如果您需要当前用户的证书,请将上述命令中的 LocalMachine 替换为 CurrentUser

    【讨论】:

      【解决方案2】:

      在 PFX 文件中,私钥证书都被加密(使用相同的密码)。如果您不知道密码,您将无法获得证书。如果你知道的话,certutil -dump 就足够了。

      【讨论】:

        猜你喜欢
        • 2019-03-26
        • 1970-01-01
        • 2016-07-08
        • 2013-04-30
        • 1970-01-01
        • 2017-09-14
        • 1970-01-01
        • 2017-08-02
        • 2016-03-23
        相关资源
        最近更新 更多