设置带有签名证书的ssl服务器套接字

Fra*_*aar 5 c# ssl x509certificate

我正在尝试创建一个侦听端口并使用ssl进行身份验证的简单服务器.我有文件

server.crt
server.key
my-ca.crt
Run Code Online (Sandbox Code Playgroud)

通过openssl教程获得(http://www.vanemery.com/Linux/Apache/apache-SSL.html).my-ca.crt是我自己的CA证书,server.crt包含x509服务器证书(使用my-ca.crt签名)并且server.key是相应的私钥.

我现在不知道如何在c#中加载这三个文件; 我有类似的东西

serverCertificate = new X509Certificate2("server.crt", "secret_password");
sslStream.AuthenticateAsServer(serverCertificate, false, SslProtocols.Tls, true);
Run Code Online (Sandbox Code Playgroud)

这不起作用(我得到了

Unhandled Exception: System.NotSupportedException: The server mode SSL must use a certificate with the associated private key.
Run Code Online (Sandbox Code Playgroud)

)但我不知道如何添加server.key和/或my-ca.crt.

Ole*_*leg 3

X509Certificate2以表格形式使用

serverCertificate = new X509Certificate2("server.pfx", "secret_password");
Run Code Online (Sandbox Code Playgroud)

您应该以 PKCS12 格式保存证书。请参阅http://www.madboa.com/geek/openssl/#cert-pkcs12http://www.openssl.org/docs/apps/pkcs12.html