如何正确设置密码提供者为New-SelfSignedCertificate?

时间:2019-06-29 10:38:48

标签: powershell certificate x509certificate

我使用Windows 10,并希望使用自定义加密提供程序创建自签名证书以进行应用程序测试。这是我的脚本:

 New-SelfSignedCertificate -CertStoreLocation "Cert:\LocalMachine\My" -Provider "Microsoft Base Cryptographic Provider v1.0" -Subject "CN=test" -KeyUsage "CertSign", "CRLSign", "DigitalSignature", "NonRepudiation" -KeyExportPolicy Exportable -NotAfter (Get-Date).AddYears(40) -Type Custom

但是我得到这个错误:

New-SelfSignedCertificate : CertEnroll::CX509Enrollment::_CreateRequest: Provider type not defined. 0x80090017 (-2146893801 NTE_PROV_TYPE_NOT_DEF)
At line:1 char:2
+  New-SelfSignedCertificate -CertStoreLocation "Cert:\LocalMachine\My" ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-SelfSignedCertificate], Exception
    + FullyQualifiedErrorId : System.Exception,Microsoft.CertificateServices.Commands.NewSelfSignedCertificateCommand

我应该使用Microsoft Base Cryptographic Provider v1.0作为提供者(因为我的测试应用仅接受该提供者提供的证书),但是出现了以上错误。我应该如何设置错误消息中提到的 Porvider类型?!

2 个答案:

答案 0 :(得分:1)

使用旧式CSP时,必须在提供密钥类型的地方指定-KeySpec参数:密钥交换或签名。根据您的值,该值应为AT_SIGNATURE,即-KeySpec 2

答案 1 :(得分:0)

找到答案!它只能在Windows Server环境中使用,而不能在我的Win 10客户端中使用!