Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell Can';使用.NET API导入时,无法将证书绑定到SSL_Powershell_Ssl_X509certificate_X509certificate2 - Fatal编程技术网

Powershell Can';使用.NET API导入时,无法将证书绑定到SSL

Powershell Can';使用.NET API导入时,无法将证书绑定到SSL,powershell,ssl,x509certificate,x509certificate2,Powershell,Ssl,X509certificate,X509certificate2,我已经使用openssl创建了一个自签名SSL证书。当我使用.NETAPI导入证书时,我无法使用netsh将其绑定到我的网站。我正在使用PowerShell导入证书: $Certificate = New-Object 'security.Cryptography.X509Certificates.X509Certificate2' $PathToCertificate $keyFlags = [Security.Cryptography.X509Certificates.X509KeyStor

我已经使用openssl创建了一个自签名SSL证书。当我使用.NETAPI导入证书时,我无法使用netsh将其绑定到我的网站。我正在使用PowerShell导入证书:

$Certificate = New-Object 'security.Cryptography.X509Certificates.X509Certificate2' $PathToCertificate
$keyFlags = [Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet
$keyFlags = $keyFlags -bor [Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet
$keyFlags = $keyFlags -bor [Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable

$store = New-Object 'Security.Cryptography.X509Certificates.X509Store' 'My','LocalComputer'
$store.Open( 'ReadWrite' )
$store.Remove( $Certificate )
$store.Add( $Certificate )
$store.Close()
然后我使用
netsh
绑定到证书:

netsh http add sslcert ipport=0.0.0.0:443 certhash=<thumbprint> appid=<app ID>
netsh http add sslcert ipport=0.0.0.0:443 certhash=appid=
第一次运行成功,但后续尝试失败,出现以下错误:

SSL证书添加失败,错误:1312
指定的登录会话不存在。它可能已经被终止了

但是,当我通过证书MMC/管理单元手动导入证书时,运行
netsh
命令从未遇到任何问题

我在一些Windows 7和Windows 2012 R2计算机上看到此错误。奇怪的是,我们一半以上的电脑都没有这个问题。我是否添加了错误的证书?我可能生成了一个坏证书吗?

我撒谎了。看起来我以为我在上面的代码中设置了密钥存储标志。事实证明,我是在脚本的另一部分加载证书的,它没有指定正确的密钥存储标志。在纠正我的脚本,使它真正做到我声称它做的,一切工作