簡體   English   中英

SslStream.AuthenticateAsServer 拋出服務器模式 SSL 必須使用具有關聯私鑰的證書

[英]SslStream.AuthenticateAsServer throws The server mode SSL must use a certificate with the associated private key

干杯,

我有一個帶有 CERTIFICATE 部分和 PRIVATE KEY 部分的 *.crt 我加載此證書

X509Certificate2 serverCertificate = X509Certificate2.CreateFromCertFile("Data\\certificate.crt");

現在我想啟動一個安全的 TcpListener,但得到

SslStream sslStream = new SslStream(client.GetStream(), false);
sslStream.AuthenticateAsServer(serverCertificate, clientCertificateRequired: true, checkCertificateRevocation: true);

錯誤“服務器模式 SSL 必須使用具有關聯私鑰的證書”...

有什么問題?

此答案適用於 C# .NET

對於 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

執行 sslStream.AuthenticateAsServer(serverCertificate, ..) 時,您應該加載 PFX 文件和密碼,而不是 CER 文件,這樣就不需要在客戶端機器上注冊。 如果有效,請告訴我在此之后我有問題:P

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM