Zdravím, snažím se rozběhnout sslstream s certifikatem a privatekey, ale bohužel mě to vyhodi error, že to potřebuje ten privateKey ... Ale já bohužel nevím jak ho tam dostat. Pomůže mi někdo? Kód zde
private static void SSL()
{
TcpListener sslServer = new TcpListener(IPAddress.Parse(LocalHost), LocalSSLPort);
try { sslServer.Start(); WriteLine("[SSL] listening on " + LocalHost + ":" + LocalSSLPort, ConsoleColor.Yellow); }
catch { WriteLine("Error : Port " + LocalSSLPort + " in use!", ConsoleColor.Red); }
X509Certificate cert = X509Certificate.CreateFromCertFile("data/cert.pem");
X509Certificate2 cert2 = new X509Certificate2("data/cert.pem", "data/cert.key");
while (true)
{
TcpClient client = sslServer.AcceptTcpClient();
Write("[" + DateTime.Now.ToString("HH:mm:ss") + "] ", ConsoleColor.Cyan);
Write("[SSL] ", ConsoleColor.Red);
Write("receiving from " + client.Client.RemoteEndPoint + "\r\n", ConsoleColor.Green);
SslStream sslStream = new SslStream(client.GetStream(), false);
sslStream.AuthenticateAsServer(cert2, false, SslProtocols.Ssl3, true);
//sslStream.AuthenticateAsServer(cert, false, SslProtocols.Ssl3, true);
//byte[] message = new byte[BlockSize];
//int ReadBytes = sslStream.Read(message, 0, BlockSize);
//ASCIIEncoding encoder = new ASCIIEncoding();
//Console.WriteLine(encoder.GetString(message, 0, ReadBytes));
}
}
Error mi to hodi tady -> sslStream.AuthenticateAsServer(cert2, false, SslProtocols.Ssl3, true);
a ten error je tohle The server mode SSL must use a certificate with the associated private key.