I have a certificate someCert.cer
. I imported it into my local certificates store using MMC utility. My C# application is able to access it using following code:
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
X509Certificate2 certificate = null;
store.Open(OpenFlags.ReadOnly);
try
{
var certificateCollection = store.Certificates.Find(X509FindType.FindByThumbprint, "THUMBPRINT", false);
certificate = certificateCollection[0];
}
finally
{
store.Close();
}
The application exposes TCP socket and when I try to connect to it with my client app I get exception:
The server mode SSL must use a certificate with the associated private key
Indeed my certificate's PrivateKey property is empty. Did I import my certificate incorrect or should I do something with the certificate before importing it into the store?
My server authentication code looks like that:
stream.AuthenticateAsServerAsync(certificate, false, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12, true);