如何正确地将加密提供程序设置为 New-SelfSignedCertificate?

How to Set Cryptographic Provider to New-SelfSignedCertificate Properly?

我使用 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 Type?!

找到答案!它只适用于 Windows 服务器环境,不适用于我的 win 10 客户端!

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