title: Does SSH.NET accept only OpenSSH format of private key? If not, what are the restrictions?
body: <p>The manual doesn't indicate such, but some Googling returns pages from the turn of the decade (such as <a href="https://www.jokecamp.com/blog/connecting-to-sftp-with-key-file-and-password-using-ssh-net/" rel="noreferrer">this</a>) suggesting that this at least <em>used</em> to be the case.  We have code like this:</p>
  
  <pre><code>var privateKeyAuthenticationMethod =
      new PrivateKeyAuthenticationMethod(userName, new PrivateKeyFile(privateKeyLocation));
  var connInfo =
      new ConnectionInfo(
          ftpSettings.HostAddress, ftpSettings.UserName, privateKeyAuthenticationMethod);
  using (var client = new SftpClient(connInfo))
  {
      client.Connect();
      client.UploadFile(memStreamData, destination);
  }
  </code></pre>
  
  <p>This hooks into a private key that we have used successfully via SCP2 (Secure Copy 2 as detailed <a href="https://www.ssh.com/manuals/client-user/44/scp2.html" rel="noreferrer">here</a>) - it is 2048 DSA, which is listed as valid in the SSH.NET documentation. The key uses an ssh.com format like:</p>
  
  <pre class="lang-none prettyprint-override"><code>---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----
  Subject: &lt;FID name&gt;
  Comment: "2048-bit dsa, &lt;FID name&gt;@&lt;Server name&gt;, Mon Apr 24 201\
   7 15:49:36 +0100"
  &lt;ENCRYPTED KEY&gt;
  ---- END SSH2 ENCRYPTED PRIVATE KEY ----
  </code></pre>
  
  <p>However, there is a <code>Regex</code> within the private key handling portion of SSH.NET that fails to match our private key, and so throws an exception:</p>
  
  <pre class="lang-none prettyprint-override"><code>ERROR 2017-05-10 15:31:43 UTC [T: 474] – Invalid private key file.
  ERROR 2017-05-10 15:31:43 UTC [T: 474] – at Renci.SshNet.PrivateKeyFile.Open(Stream privateKey, String passPhrase)
  </code></pre>
  
  <p>It does however match if we convert the key to OpenSSH format, but this is not necessarily something that we can use in production due to business constraints.</p>
  
  <p>Does anyone know exactly what the restrictions are on Private Key format for SSH.NET please?  We are not sure if this time if we need to abandon SSH.NET for some other SFTP wrapper library, write our own, or what.</p>