C# windows中本地主机使用AuthenticateTaserver()的x509证书

C# windows中本地主机使用AuthenticateTaserver()的x509证书,c#,openssl,x509certificate,sslstream,makecert,C#,Openssl,X509certificate,Sslstream,Makecert,您好,我想创建X509Certificate,以便在windows 10 loopbak上的SslStream.authenticatesServer()中使用。 我尝试使用OpenSsl和Makecert脚本创建证书,但证书不起作用。 请帮帮我。 我的代码: X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine); store.Open(OpenFlags.R

您好,我想创建X509Certificate,以便在windows 10 loopbak上的SslStream.authenticatesServer()中使用。 我尝试使用OpenSsl和Makecert脚本创建证书,但证书不起作用。 请帮帮我。 我的代码:

X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
                    store.Open(OpenFlags.ReadOnly);

                    RawStringData = RawStringData.Replace("CONNECT ", "GET https://");
                    RawStringData = RawStringData.Replace(":443", "/");
                    RawStringData = RawStringData.Replace("Proxy-Connection", "Connection");
                    RawByteArrayData = Encoding.ASCII.GetBytes(RawStringData);
                    Port = 443;
                    ServerSocket.Connect(HostEntry.AddressList[0], Port);
                    HttpsStream = new SslStream(new NetworkStream(ServerSocket));
                    HttpsStream.AuthenticateAsClient(Host);
                    HttpsStream.Write(RawByteArrayData);
                    int Count = HttpsStream.Read(NewData, 0, NewData.Length);
                    string pfxpath = @"D:\test.pfx";
                    X509Certificate2 cert = new X509Certificate2(File.ReadAllBytes(pfxpath));
                    byte[] pfxData = File.ReadAllBytes(pfxpath);

                    cert = new X509Certificate2(pfxData,"", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);

                    X509Certificate x509 = store.Certificates.Find(X509FindType.FindByIssuerName, "localhost", false)[0];
                    ssl = new SslStream(new NetworkStream(A) , false , Verification , null );
                    ssl.AuthenticateAsServer(cert , false, System.Security.Authentication.SslProtocols.Tls, true);
                    ssl.Write(NewData);

你能告诉我们到目前为止你尝试了什么以及失败的原因吗?请参阅下面帖子中的我的解决方案:@DragonThinks我使用Openssl和makecert创建了许多证书,并将它们安装到受信任的根目录中,然后进行测试。但当程序接收到authenticatesServer()时,程序会无限期地被阻止。我想将数据发送到Web浏览器。我在LocalMachine和CurrentUser中的受信任根目录中测试所有证书。@jdweng我看到了,但和其他测试一样,程序被无限期阻止