gpt4 book ai didi

c# - 如何让 XSockets 与 HTTPS 和 WSS 一起工作?

转载 作者:太空宇宙 更新时间:2023-11-03 15:51:17 26 4
gpt4 key购买 nike

当我使用“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
}
}

我收到以下错误:

ERROR 2014/09/07-19:50:16 Could not start XSockets server. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.Cryptography.CryptographicException: The system cannot find the file specifed.

at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(String fileName) at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password) at NET.Server.MyCustomConfig2..ctor() in C:\MyProjects\NET.Server\Program.cs:line 369 --- End of inner exception stack trace ---

它在我用评论标记的第 369 行出错。我不知道“file.name”应该是什么。如何获取 SSL 证书的“file.name”?我一直在使用我制作的自签名测试证书,但我不知道从哪里获得它的“file.name”我希望有一个我可以引用的可运行代码的实际示例,而不必查看通用的东西。

有人有完整的 XSockets WSS 实现示例吗?我正在使用 XSockets.Net 版本 3.0.6,谢谢。

最佳答案

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

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

示例 1 是为了防止您拥有实际的文件证书并且不想导入它。

关于c# - 如何让 XSockets 与 HTTPS 和 WSS 一起工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25716145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com