【问题标题】:How Can I Get XSockets to Work With HTTPS and WSS?如何让 XSockets 与 HTTPS 和 WSS 一起工作?
【发布时间】: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


    【解决方案1】:

    如果您在需要的机器上安装了证书,则使用 Sample1(听起来这就是您要寻找的)。

    您可以使用 certmanager certmgr.msc 在您的计算机中查找证书并按名称查找。

    示例 1 是在您拥有实际文件证书但不想导入它的情况下。

    【讨论】:

      猜你喜欢
      • 2016-09-07
      • 2018-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-29
      • 2023-02-02
      • 2012-12-09
      • 2014-06-06
      相关资源
      最近更新 更多