正如标题所示,我想在不使用 OpenSSL 或任何其他第三方工具的情况下导出我的私钥。如果我需要一个.cer
文件或.pfx
文件,我可以通过 MMC 或 PowerShell 轻松导出这些文件,pkiclient
但我找不到获取私钥的方法。
https://docs.microsoft.com/en-us/powershell/module/pkiclient/export-certificate?view=win10-ps
使用像https://www.sslshopper.com/ssl-converter.html这样的在线工具是不行的。
PS版本:
PS C:\Users\oscar> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.17134.228
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.228
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
我可以像这样得到公钥:
(Get-PfxCertificate -FilePath C:\Users\oscar\Desktop\localhost.pfx).GetPublicKey()
并像这样导出整个证书:
(Get-PfxCertificate -FilePath C:\Users\oscar\Desktop\localhost.pfx).GetRawCertData()
结果来自
PS C:\Users\oscar> $mypwd = ConvertTo-SecureString -String "MyPassword" -Force -AsPlainText
PS C:\Users\oscar> $mypfx = Get-PfxData -FilePath C:\Users\oscar\Desktop\localhost.pfx -Password $mypwd
PS C:\Users\oscar> $mypfx
OtherCertificates EndEntityCertificates
----------------- ---------------------
{} {[Subject]...
PS C:\Users\oscar> $mypfx.EndEntityCertificates
Thumbprint Subject
---------- -------
8ED4971564E35099D6DB490C3756E2AD43AAAAAA CN=localhost
测试了来自@Brad 的命令,但出现以下错误。
私钥不是纯文本可导出的
certutil -exportPFX -p "myPassword" -privatekey -user my <Certificate Serial Number> C:\localhost.pfx
与 MMC 证书中的证书导出向导类似,仅.pfx
在包含密钥时导出到可用。