[英]SslStream.AuthenticateAsServer throws The server mode SSL must use a certificate with the associated private key
Cheers,干杯,
I have a *.crt with a CERTIFICATE section and a PRIVATE KEY section I load this certificate with我有一个带有 CERTIFICATE 部分和 PRIVATE KEY 部分的 *.crt 我加载此证书
X509Certificate2 serverCertificate = X509Certificate2.CreateFromCertFile("Data\\certificate.crt");
Now I want to start a secure TcpListener, but get at现在我想启动一个安全的 TcpListener,但得到
SslStream sslStream = new SslStream(client.GetStream(), false);
sslStream.AuthenticateAsServer(serverCertificate, clientCertificateRequired: true, checkCertificateRevocation: true);
the error "The server mode SSL must use a certificate with the associated private key"...错误“服务器模式 SSL 必须使用具有关联私钥的证书”...
Whats the problem?有什么问题?
This answer is for C# .NET此答案适用于 C# .NET
For HTTPS calls, the example is provided on MSDN using TCP Listner and TCP Client.对于 HTTPS 调用,该示例在 MSDN 上使用 TCP Listner 和 TCP Client 提供。
https://docs.microsoft.com/en-us/dotnet/api/system.net.security.sslstream?redirectedfrom=MSDN&view=netframework-4.7.2#Anchor_5 https://docs.microsoft.com/en-us/dotnet/api/system.net.security.sslstream?redirectedfrom=MSDN&view=netframework-4.7.2#Anchor_5
When doing sslStream.AuthenticateAsServer(serverCertificate, ..) you should load a PFX file along with password, instead of CER file, then it will not require registration on client machine.执行 sslStream.AuthenticateAsServer(serverCertificate, ..) 时,您应该加载 PFX 文件和密码,而不是 CER 文件,这样就不需要在客户端机器上注册。 if works please tell me i have problems after this :P
如果有效,请告诉我在此之后我有问题:P
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.