Generating a certificate for AuthenticateAsServer
===

I am trying to fix <a href="http://code.google.com/p/flowlib/">FlowLib</a> which seems to have been abandoned in 2009.

One of the class, TcpConnections.cs (FlowLib.Connections.TcpConnection) is giving me problems. It is trying to setup a SslStream, but the AuthenticateAsServer method doesn't seem to accept any certificate.

Part of the code : 

    secStream = new SslStream(client.GetStream(),false,
        new RemoteCertificateValidationCallback(OnRemoteCertificateValidation),
        new LocalCertificateSelectionCallback(OnLocalCertificateSelection));

     SslProtocols protocol = SslProtocols.Default;

     X509Certificate cert = new X509Certificate2(@"cert.pfx");
     secStream.AuthenticateAsServer(cert, false, protocol, false);

I have tried multiple ways to create a certificate but for all certificate it give the following exception : 

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

The code included in the earlier snippet is my latest attempt to get a working certificate 
(taken from another SO answer), earlier it simply created a new certificate using :

     secStream.AuthenticateAsServer(new X509Certificate(), true, protocol, true);

And that code is from the release version, so I am guessing somewhere between 2009 and now the way AuthenticateAsServer worked has changed.

Can someone help me get this to work?

PS : The complete code is available at <a href="http://code.google.com/p/flowlib/downloads/detail?name=FlowLib20090103.zip&can=2&q=">here</a> So you can try it out yourself.