简体   繁体   English

使用C#中的p12证书从SFTP下载文件

[英]Download file from SFTP with p12 certificate in C#

I have tried searching for the above and found SSH.NET, but I am not sure: 我尝试搜索以上内容并找到SSH.NET,但不确定:

  1. If it suits my case. 如果适合我的情况。
  2. How to use it the way I need it to work. 如何以我需要它的方式使用它。

I have a client with an SFTP - to which he connects using a normal third party tool like FileZilla. 我有一个带有SFTP的客户端-他使用普通的第三方工具(如FileZilla)连接到该客户端。

I have the credentials etc. and need to download files from that SFTP. 我有凭据等,需要从该SFTP下载文件。 Unfortunately for me, the SFTP requires a p12 certificate (which I have), which I do not know how to use. 对我来说不幸的是,SFTP需要一个p12证书(我有),我不知道该如何使用。 I have not yet worked with SFTP's. 我尚未使用SFTP。 The connection is: "interactive" 连接是:“交互式”

For a "normal" FTP I would simply get the response stream of a FtpRequest and cast its information to whatever I need it to be. 对于“普通” FTP,我只需获取FtpRequest的响应流并将其信息转换为所需的信息即可。

Question: How do I use a p12 certificate to establish a connection to a SFTP using C# without buying one of the commercial third party libraries? 问题: 如何在不购买任何商业第三方库的情况下如何使用p12证书通过C#与SFTP建立连接?

I would be thankful, for both direct tips, but also reading material for the topic. 我会很高兴,既有直接的技巧,也有阅读该主题的材料。

Are you sure you want to use the SFTP? 您确定要使用SFTP吗? I've never seen anyone using P12 key with the SSH/SFTP. 我从未见过有人将P12密钥与SSH / SFTP一起使用。 Maybe you mistake the SFTP with the FTPS [FTP over TLS/SSL]? 也许您将SFTP与FTPS [基于TLS / SSL的FTP]搞混了?

Anyway, the NET.SSH library supports only OpenSSH and ssh.com private key file formats. 无论如何,NET.SSH库仅支持OpenSSH和ssh.com私钥文件格式。 So you need to convert your P12 key to either of them. 因此,您需要将您的P12密钥转换为任意一个。

Quote from Extract public/private key from PKCS12 file for later use in SSH-PK-Authentication : 引用PKCS12文件中的提取公钥/私钥,以供以后在SSH-PK-Authentication中使用

You can use following commands to extract public/private key from a PKCS#12 container: 您可以使用以下命令从PKCS#12容器中提取公钥/私钥:

  • PKCS#1 Private key PKCS#1私钥

     openssl pkcs12 -in yourP12File.pfx -nocerts -out privateKey.pem 
  • Certificates: 证书:

     openssl pkcs12 -in yourP12File.pfx -clcerts -nokeys -out publicCert.pem 

First of all you seem to confuse SFTPwith FTP-over-SSL. 首先,您似乎将SFTP与基于SSL的FTP混淆了。 These are two different protocols . 这是两种不同的协议 From your question it seems that you need FTP-over-SSL. 从您的问题来看,您似乎需要基于SSL的FTP。

In simple cases where you need to just download a file, FtpWebRequest class of .NET will work. 在仅需要下载文件的简单情况下,.NET的FtpWebRequest类将起作用。 In more complex cases third-party libraries are required. 在更复杂的情况下,需要第三方库。

If you need to deal with SFTP, the situation is more complicated. 如果您需要处理SFTP,情况会更加复杂。 SSH doesn't usually work with X.509 certificates (such configuration is possible but is almost never used). SSH通常不适用于X.509证书(可以进行这种配置,但几乎从未使用过)。 You won't get this functionality with open-source libraries. 开源库不会提供此功能。

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

相关问题 在 C# selenium 中接受证书 (.p12) - Accept Certificate (.p12) in C# selenium 可以在 C# 中使用带有 CA 证书的 a.p12 文件而不将它们导入证书存储 - Can a .p12 file with CA certificates be used in C# without importing them to certificate store 如何使用C#从PKCS#12(.p12)文件获取私钥 - How to get private key from PKCS#12 (.p12) file using C# 如何在 C# 中为 DSA 密钥对创建带有自签名证书的 PKCS12 p12 文件? - How can I create a PKCS12 p12 file with selfsigned certificate for DSA keypair in C#? 自动安装 p12 证书文件 - automate installation of p12 certificate file 将 pfx/p12 文件导入智能卡 C# - Importing pfx/p12 file into smartcard c# 如何发送 iOS - 带有 P12 证书的 APN 通知 - C# 样本 - How to send iOS - APN Notification With P12 Certificate - C# Samples 如何在C#中创建PKCS12 .p12文件? - How do I create a PKCS12 .p12 file in C#? AWS SNS从Apple APNS的.p12文件获取证书和私钥 - AWS SNS Get Certificate and Private key from .p12 file for Apple APNS 如何使用 p7b 证书加密 zip 文件并使用 p12 对其进行签名 - how to encrypt zip file with p7b certificate and sign it with p12
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM