views:

44

answers:

1

I'm trying to make a simple server which listens on a port and authenticates with ssl. I have files

server.crt
server.key
my-ca.crt

obtained with a openssl tutorial (http://www.vanemery.com/Linux/Apache/apache-SSL.html). my-ca.crt is my own CA certificate, server.crt contains the x509 server certificate (signed with my-ca.crt) and server.key is the corresponding private key.

I now don't know how to load these three files in c#; I have something like

serverCertificate = new X509Certificate2("server.crt", "secret_password");
sslStream.AuthenticateAsServer(serverCertificate, false, SslProtocols.Tls, true);

which doesn't work (I get an

Unhandled Exception: System.NotSupportedException: The server mode SSL must use a certificate with the associated private key.

) but I have no clue how to add the server.key and/or my-ca.crt.

A: 

To use X509Certificate2 in the form

serverCertificate = new X509Certificate2("server.pfx", "secret_password");

you should save certificate in PKCS12 format. See http://www.madboa.com/geek/openssl/#cert-pkcs12 and http://www.openssl.org/docs/apps/pkcs12.html

Oleg