gpt4 book ai didi

powershell - New-SelfSignedCertificate 不生成可导出 key

转载 作者:行者123 更新时间:2023-12-05 03:50:01 26 4
gpt4 key购买 nike

我正在尝试使用 New-SelfSignedCertificate cmdlet 生成可导出 key ,但我不能。

这是我的代码:

$certFilePath = "C:\certs"
$certStoreLocation = "Cert:\LocalMachine\My"
$pwd = "p@ssw0rd"

$cert = New-SelfSignedCertificate `
-KeyFriendlyName "Development Cert" `
-KeyDescription "Development Cert" `
-KeyAlgorithm "RSA" `
-DnsName @("*.dev.local", "localhost") `
-NotBefore (Get-Date).AddYears(-1) `
-NotAfter (Get-Date).AddYears(50) `
-KeyUsage CertSign, CRLSign, DataEncipherment, DigitalSignature, NonRepudiation `
-KeyUsageProperty All `
-KeyLength 2048 `
-KeyLocation $certFilePath `
-CertStoreLocation $certStoreLocation `
-KeyExportPolicy Exportable `
-KeyProtection None `
-Type Custom

$certThumb = $cert.Thumbprint
$certPath = "$certStoreLocation\$certThumb"
$cert | Export-PfxCertificate -FilePath "$certFilePath\$certThumb.pfx" -Password (ConvertTo-SecureString -String $pwd -AsPlainText -Force)
Export-PfxCertificate : Cannot export non-exportable private key.
At line:24 char:9
+ $cert | Export-PfxCertificate -FilePath "$certFilePath\$certThumb.pfx ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Export-PfxCertificate], Win32Exception
+ FullyQualifiedErrorId : System.ComponentModel.Win32Exception,Microsoft.CertificateServices.Commands.ExportPfxCertificate

请注意,我专门告诉它生成一个可导出的 key ,但它没有。

有什么想法吗?

最佳答案

删除说的部分:

-KeyLocation $certFilePath `

...解决问题。

关于powershell - New-SelfSignedCertificate 不生成可导出 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63688638/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com