【问题标题】:How to request a exportable certificate using PowerShell?如何使用 PowerShell 请求可导出证书?
【发布时间】:2020-07-28 08:23:28
【问题描述】:

请参考Get-Certificate
我尝试使用 PowerShell 请求证书,它有效,但证书不可导出,这是我的命令:

Get-Certificate -Template "MyComputer" -SubjectName "CN=corey.com" -CertStoreLocation cert:\LocalMachine\My

当我尝试导出证书时,它失败了。

Export-PfxCertificate -Cert cert:\LocalMachine\My\$Thumbprint -FilePath C:\corey.com.pfx -Password $mypwd

错误信息:

Export-PfxCertificate:无法导出不可导出的私钥。

我找不到任何参数,如 Exportable 或属性供我使用 Get-Certificate 命令。有没有办法使用 PowerShell 请求/制作可导出的证书?

【问题讨论】:

  • @Sceptalist 感谢分享,但我的关键问题是如何在使用 PowerShell “请求”时使证书可导出,知道吗?
  • @Corey 安装证书时,必须将其标记为可导出,如果不这样做,则为单向过程。
  • 我认为这会给您一个来自注册服务器的子证书,这基本上意味着您需要从注册服务器本身导出 Pfx。另一种选择是使用 New-SelfSignedCertificate 创建一个自签名证书,然后您将能够从您所在的服务器导出 pfx。

标签: windows powershell x509certificate


【解决方案1】:

因为使用Get-Certificate时没有参数可以导出,所以我使用certreq作为替代来实现我的目标并在这里发布希望可以帮助其他人。

首先准备一个信息文件,将Exportable设置为TRUE

$file = @'
[NewRequest]
Subject = "CN=corey.com"
KeyLength = 2048
Exportable = TRUE
[RequestAttributes]
CertificateTemplate = "MyTemplate"
'@

Set-Content temp.inf $file

其次,键入以下命令。

# create a new request from an .inf file
certreq -new temp.inf temp.req

# submit a request to the certificate authority
certreq -submit -config CAHostName\CAName temp.req temp.cer

# accept and install a response to a certificate request
certreq -accept temp.cer

最后,导出证书并为其分配密码。

$mypwd = ConvertTo-SecureString -String $password -Force -AsPlainText
Export-PfxCertificate -Cert cert:\LocalMachine\My\$Thumbprint -FilePath C:\corey.com.pfx -Password $mypwd

更多详情请见certreq - Microsoft Docs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-21
    • 2013-04-25
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    • 2014-09-08
    • 1970-01-01
    • 2015-07-29
    相关资源
    最近更新 更多