Windows中用于使用AuthenticateAsServer()的本地主机的x509证书

时间:2018-06-27 10:21:37

标签: c# openssl x509certificate sslstream makecert

嗨,我想在Windows 10 loopbak上的SslStream.AuthenticateAsServer()中创建要使用的X509证书。 我尝试使用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);

0 个答案:

没有答案