无法注册一个C#生成使用Netsh(错误1312)自签名SSL证书 [英] Can't register a C# generated selfsigned SSL certificate with netsh (error 1312)
问题描述
我创建通过C#(BouncyCastle的)自签名的SSL证书。它显示了在本地计算机/个人存储,准确看起来像微软已经存在的本地主机证书。如果我表现出的属性,它说:
I have created a self-signed SSL certificate via C# (bouncycastle). It shows up in the local computer / personal store and looks exactly like the already existing localhost certificate from Microsoft. If I show the properties, it says:
SSL证书添加失败,错误:1312指定的登录会话不
不存在。它可能已经被终止。
SSL Certificate add failed, Error: 1312 A specified logon session does not exist. It may already have been terminated.
不过,如果我想注册通过的netsh这个证书,我得到一个错误:
However, if I want to register this certificate via netsh, I get an error:
netsh.exe http add sslcert ipport=0.0.0.0:{0} certhash={1} appid={2}
APP-ID是在AssemblyInfo.cs中指定的GUID。 CERTHASH
是从属性页证书的。
我发现了几个原因为什么会在众多的博客文章发生了:
I found several reasons why this can happen in numerous blog posts:
- 使用更高的权限(我这样做)
- 确保您的证书是注册在本地计算机,而不是在当前用户 - 我有这个 。
- 确保证书有私钥(它,因为它是在属性dialoge方框)。
他们没有导致成功...
None of them led to a success...
推荐答案
您的问题是之前的绑定。我认为证书不正确导入。
当您加载在C#中的证书,使用方法:
Your problem is prior to the binding. I assume that the certificate is not correctly imported. When you load your certificate in C#, use:
var cert = new X509Certificate2("Path", "Pwd, X509KeyStorageFlags.MachineKeySet
| X509KeyStorageFlags.PersistKeySet
| X509KeyStorageFlags.Exportable);
和确保您将其存储在本地计算机 StoreLocation.LocalMachine
:
And make sure that you store it in the local machine StoreLocation.LocalMachine
:
var store = new X509Store(storeName, StoreLocation.LocalMachine);
store.Open(OpenFlags.MaxAllowed);
store.Add(cert);
store.Close();
这篇关于无法注册一个C#生成使用Netsh(错误1312)自签名SSL证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!