Rya*_*ies 3 .net c# windows powershell-4.0
赢 8.1 64 位。.NET 4.5。Powershell 4.0。(虽然我认为这个问题一般与 .NET 相关,而不是特定于 Powershell。)
我生成这样的自签名证书:
New-SelfSignedCertificate -DnsName 'TheIncredibleHulk' -CertStoreLocation Cert:\CurrentUser\My
Run Code Online (Sandbox Code Playgroud)
然后我检索证书:
$Cert = Get-Item Cert:\CurrentUser\My\9E5A8322B890DA1247BD98BDAB288CA9D11CF99E
Run Code Online (Sandbox Code Playgroud)
该证书有一个私钥:
$Cert.HasPrivateKey
True
Run Code Online (Sandbox Code Playgroud)
或者是吗?
$Cert.PrivateKey
(null)
Run Code Online (Sandbox Code Playgroud)
为什么PrivateKey会员为空?如何找回私钥?
这个答案让我找到了一个解决方法。该问题是由默认提供程序引起的,但在Win10 版本 New-SelfSignedCertificate中,您可以指定提供程序,如下所示。
New-SelfSignedCertificate -DnsName HulkSmash -CertStoreLocation Cert:\LocalMachine\My -KeyAlgorithm RSA -KeyLength 2048 -KeyExportPolicy Exportable -KeyProtection None -Provider 'Microsoft Enhanced RSA and AES Cryptographic Provider'
Run Code Online (Sandbox Code Playgroud)
小智 5
对于遇到此问题的其他任何人,我怀疑该问题与 New-SelfSignedCertificate 使用的存储提供程序有关(请参阅http://blogs.technet.com/b/vishalagarwal/archive/2010/03/30/verifying-the -private-key-property-for-a-certificate-in-the-store.aspx,它讨论了 Microsoft 软件密钥存储提供程序和 .NET 类的问题)。technet上有一个 powershell 脚本可以创建自签名证书,并且默认使用不同的存储提供程序。