【发布时间】:2014-09-08 00:58:25
【问题描述】:
当我使用“ws://”URL 时,我的 XSockets.Net 代码运行良好,但是当我尝试实现安全版本时,我无法让它运行。
我使用以下 C# 示例代码作为指导:
//Sample 1 - Certificate from store public class ChuckNorrisConfig :
ConfigurationSetting {
public MyCustomConfig1() : base(new Uri("wss://my.server.ip.address:4502"))
{
this.CertificateLocation = StoreLocation.LocalMachine;
this.CertificateSubjectDistinguishedName = "cn=localmachine";
}
}
//Sample 2 - X509Certificate2
public class MyCustomConfig2 : ConfigurationSetting {
public ChuckNorrisConfig() : base(new Uri("wss://my.server.ip.address:4502"))
{
this.Certificate = new X509Certificate2("file.name", "password");// line 369
}
}
我收到以下错误:
错误 2014/09/07-19:50:16 无法启动 XSockets 服务器。 System.Reflection.TargetInvocationException:已引发异常 通过调用的目标。 ---> System.Security.Cryptography.CryptographicException:系统不能 找到指定的文件。
在 System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 小时)在 System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(字符串 文件名)在 System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(字符串 文件名,对象密码,X509KeyStorageFlags keyStorageFlags)在 System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(字符串 NET.Server.MyCustomConfig2..ctor() 中的文件名、字符串密码) C:\MyProjects\NET.Server\Program.cs:第 369 行 --- 结束 内部异常堆栈跟踪---
它在我用评论标记的第 369 行出错。 我不知道“file.name”应该是什么。如何获取 SSL 证书的“file.name”?我一直在使用我制作的自签名测试证书,但我不知道从哪里获得它的“file.name” 我希望有一个我可以参考的可运行代码的实际示例,而不必查看通用的东西。
有没有人有一个完整的 XSockets WSS 实现示例?我正在使用 XSockets.Net 3.0.6 版,谢谢。
【问题讨论】:
标签: c# ssl ssl-certificate xsockets.net