如何使用openssl C#wrapper连接到openssl服务器 [英] How do I connect to an openssl server using openssl C# wrapper

查看:94
本文介绍了如何使用openssl C#wrapper连接到openssl服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经获得了我应该用来连接服务器的证书,密钥和链文件(.crt,.key和.pem)。我尝试使用openssl创建.pfx文件,并将其与TcpClient / SslStream / authenticate一起用作客户端。它没用。我现在理解的是,如果服务器使用openssl,客户端也必须(或者痛苦地了解openssl如何处理它并编写大量代码)。我在项目中包含了可用的openssl C#包装器,但不知道如何使用它连接到服务器。有效的openssl命令行是......

openssl s_client -key provided.key -cert provided.crt -CAfile providedChain.pem -connect 127.0.0.1:12345

这个说法有效,但我如何使用包装器在C#中做同样的事情?



我尝试过的事情:



我尝试过标准的TcpClient,并在连接回调中创建了SslStream并尝试作为客户端进行身份验证。该调用需要证书,但据我所知,它是一个包含证书信息和密钥的文件。我用openssl来结合这两个但是没有用。服务器踢我了,因为初始握手没有事件工作(不要进入认证部分)。

I've been given a certificate, key, and chain file (.crt, .key, and .pem) that I'm supposed to use to connect to a server. I've tried using openssl to create a .pfx file and used it with a TcpClient / SslStream / authenticate as client. It didn't work. What I understand now is that if the server uses openssl, the client must also (or painfully learn how openssl does its thing and write a lot of code). I've included the available openssl C# wrapper in a project but have no clue how to connect to the server using it. The openssl command line that works is...
openssl s_client -key provided.key -cert provided.crt -CAfile providedChain.pem -connect 127.0.0.1:12345
This statement works but how do I use the wrapper to do the same thing in C#?

What I have tried:

I've tried the standard TcpClient and in the connection callback, created the SslStream and attempted to authenticate as client. The call takes a certificate but from what I understand, it is one file that contains certificate information as well as the key. I've used openssl to combine the two but that didn't work. The server kicks me out because the initial handshake doesn't event work (don't get to the authentication part).

推荐答案

谷歌搜索是你最好的朋友。 br />


我使用以下方式快速搜索: c#ssl - Google搜索 [ ^ ]然后在页面底部有以下建议: c#ssl客户端示例 - Google搜索 [ ^ ]然后将其作为第一个结果: SslStream Class(System.Net.Security) - MSDN [ ^ ]其中有一个工作示例。



如果您需要其他示例,请执行以上操作两次搜索有大量有用的材料。
Google Search is your best friend.

I did a quick search using: c# ssl - Google Search[^] which then had the following suggestion at the bottom of the page: c# ssl client example - Google Search[^] which then had this as the first result: SslStream Class (System.Net.Security) - MSDN[^] which has a working example.

If you need other examples, the above two searches has tonnes of useful material for you.


这篇关于如何使用openssl C#wrapper连接到openssl服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆