简体   繁体   English

如何使用SslStream和自签名证书实现Https Web服务器?

[英]How to implement a Https web server using SslStream and a self signed certificate?

The problem was that SslStream always read 0 bytes because the chrome web browser cannot validate the server's certificate. 问题是SslStream始终读取0个字节,因为chrome Web浏览器无法验证服务器的证书。

Refer to the msdn sample code: https://msdn.microsoft.com/en-us/library/system.net.security.sslstream(v=vs.110).aspx 请参阅msdn示例代码: https ://msdn.microsoft.com/zh-cn/library/system.net.security.sslstream( v= vs.110).aspx

I created the server side certificate with makecert.exe: 我使用makecert.exe创建了服务器端证书:

makecert    
    -pe                                     Exportable private key
    -n "CN=Test"                            Subject name
    -ss my                                  Certificate store name
    -sr LocalMachine                        Certificate store location
    -a sha1                                 Signature algorithm
    -sky signature                          Subject key type is for signature purposes
    -r                                      Make a self-signed cert
    "output.cer"                            Output filename

2. I've successfully installed the generated cert file in Local Computer -> Trusted Root Certification Authorities. 2.我已经在本地计算机->受信任的根证书颁发机构中成功安装了生成的证书文件。

  1. Launch the server and access https://localhost from the web browser 启动服务器并从Web浏览器访问https:// localhost

When calling the Read method from SslStream (which created based on a network stream), it always return 0 bytes. 从SslStream(基于网络流创建)调用Read方法时,它始终返回0字节。

Is there any steps missing so as to let the browser talk with the SslStream successfully? 是否缺少任何步骤,才能使浏览器成功与SslStream通讯?

将CN从test更改为localhost,然后chrome网络浏览器就可以与sslstream通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM