[英]How to request a exportable certificate using PowerShell?
参考获取证书
我尝试使用 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
或 property 供我与Get-Certificate
命令一起使用。 有什么方法可以使用 PowerShell 请求/制作可导出的证书吗?
因为在使用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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.