1
我很難理解爲什麼我的簡單C#SSL服務器代碼失敗。當我嘗試使用從文件系統加載的.p12文件進行「身份驗證爲服務器」時,出現錯誤。簡單的C#SSL服務器:提供給包的憑證未被識別
這裏是我的代碼:
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, 2045);
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
server.Bind(localEndPoint);
while (true)
{
server.Listen(10);
Socket client = server.Accept();
Stream clientStream = new NetworkStream(client, true);
var clientTlsStream = new SslStream(clientStream, false);
var p12Cert =
new X509Certificate2(
@"C:\Repos\ITEL-Trunk\Code\Applications\Server\bin\Debug\Configuration\Certificate_tool_signed_with_ca.p12",
"Passw0rd");
clientTlsStream.AuthenticateAsServer(p12Cert);
var cr = clientTlsStream.CanRead;
}
而這裏的異常詳細信息:
System.ComponentModel.Win32Exception was unhandled
HResult=-2147467259
Message=The credentials supplied to the package were not recognized
Source=System
ErrorCode=-2147467259
NativeErrorCode=-2146893043
的X509Certificate2對象表示 '已經私鑰=真正的',我已經試過作爲Admininstrator運行沒有運氣。其他我所見過的關於CAPI權限的SO問題,但是由於我直接從文件系統加載,所以我無法應用這些答案。