[英]How to create certificate for SslStream.AuthenticateAsServer()?
I'm trying to write a server application that uses SSL to communicate. 我正在尝试编写一个使用SSL进行通信的服务器应用程序。 After accepting a connection, I believe I have to call SslStream.AuthenticateAsServer
. 接受连接后,我相信我必须调用SslStream.AuthenticateAsServer
。 However, this expects a certificate and I do not understand how to create one. 但是,这需要一个证书,我不知道如何创建证书。
I followed the advice given in the answer to this question : 我遵循了这个问题的答案中给出的建议:
I ran the following to create a server.pfx file: 我运行以下命令来创建server.pfx文件:
makecert.exe -r -pe -n "CN=localhost" -sky exchange -sv server.pvk server.cer pvk2pfx -pvk server.pvk -spc server.cer -pfx server.pfx
Then I loaded it in code with: 然后我将其加载到代码中:
certificate = new X509Certificate2("server.pfx", "password");
However, I did that exactly, and I get a CryptographicException
saying “The specified network password is not correct.”, which is patently false because I used the password x
, which is very hard to mistype. 但是,我确实做到了这一点,并且得到了CryptographicException
说“指定的网络密码不正确。”,这显然是错误的,因为我使用的密码x
很难输入。 What am I doing wrong? 我究竟做错了什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.