Getting "invalid private key file." error
Hi,
I am new to this SFTP communication. I have received the Private_Keys.ppk file from my IT team, which is as follows, PuTTY-User-Key-File-2: ssh-rsa Encryption: aes256-cbc Comment: imported-openssh-key Public-Lines: 6 AAAAB3NzaC1yc2EAAAADAQABAAABAQCXVRQ8E0LnZ1aFepN0NaLaavip8cO+EJSp 29PBOB2pUCkua/3IXO7q3coziwdJOhPElL6vh3dHDYtuEqrXPhkEli9mruf20ZVj vI5k4VtlQh5hzjwfgujmLpSWCA0OiH+i8f7y3J3e0PqIDD1E15ZShLWCpzB9YuXM +Qq2eXs47QMJ9vUYlB6ZcMMftPBp7nQMDni+Z2IHFp4yq1XXo8wRu9pyoKG+j5T9 Vbb1voUCPwgLlcXETt3J3pzS/P+/lake7eTJytJXfhMCn2DovGBxnvHywILLPNaz HE5FVMxc/ZI8IXqpbGKvY0CRqVNNlZWLRVntjL4IOuDZYMqI1cUJ Private-Lines: 14 vXQMpVg0cnoA8nkceo5oKf86/QcWFON+Gik1gCPBkus1V60Zd2LVMAHHN0WV8836 OpZzZTUyQrCa3sM/vz9mvQwx1FyZaDNLl6goXK4acneRNHMwblobSH0AGMjCc2x/ WIPtI4gjrwZF8TTNt4eo1kxnW/4E4zilI9U6Kv3h7QTYkvlyA3G0v33y85FQwmfz maaBi/+Deayp6eGzyEASUqedb6DNVBel7KRs6D2sazywXZZs42zAVxTd+2g8B6D6 cU7a6GXSVqmxMIicYvCT/i6O5cJ+srPLrDK3yqAsOfye5SwgAq8lK3c5q/mEStlG MHKZfskOXXoaTN9XEZX6w3fxKdMHd4tSSzub4EcpHGfjIGzc55ns5WRQWNa9QJ4o vb0ImTfhODgU0OHYy6d0kio/u2BTayC543S37cojdBw76eTJOTWtqjoLDr90vrfE +oMJ26gUOJKvI7Rjy/n5bBHORwTVLyeVKKRxIqlvUqgNvRQ13etZnoGRqXmYOC2t +3v0CdM6JKB7A8OSyl9u1gjkTdj/eSOZExYzfrIJqlSEhsLH5XFbV8dz3SQW40mw BDzetChkuQ5lzW556pZwCXuOAfuOGclJI/QvPdVc1CveMa8B3j2QM7SzIf0iiGX5 8MufxkWUf2ReVKv3Onh0xdIyp0qizkztvaIV2vP5f71ZnWDAfpnALmi/HdFfvPi0 9Y9nd8z0O0HYjmCphXydgoV8nJH13zmkXq2lVqlsoeTFLpHm+fuYKGG7U5ap52lT eVvH6jmgLcyPnqVqpM23ZhBX+yxxQZR3NofkaCNpQOEChbMayr0qSbB1DwwRn11R D4N1ywXDmxKjqxWvbhfHVUCY5C+v1irpSZwmFNAGhSIIl6MYVWMsX2dfSTOSGalT Private-MAC: d11ad00691481e1f6f4bedb11621574df1c93566
While creating PrivateKeyFile object, privateKeyFile = new PrivateKeyFile(ppkfilepath);
I am getting following error, Message: invalid private key file Stack Trace: at Renci.SshNet.PrivateKeyFile.Open(Stream privateKey, String passPhrase) at Renci.SshNet.PrivateKeyFile..ctor(String fileName, String passPhrase) at Renci.SshNet.PrivateKeyFile..ctor(String fileName) at TestApp.sftpProtocol.connectSftpServer(String strHost, Int32 iPort, String strUserName, String strPassword, Int32 iTimeout, String PPKFileName) in D:\Project\SFTP Demo\demo-master\sftp_demo\SFTP\TestApp\sftpProtocol.cs:line 36
Please advice.
Note: I am able to connect to the sftp using winscp.
As far as I know, this library does not support .ppk files for the private key - you need to convert your private key to an OpenSSH format (e.g PEM).
Hi,
I'm having a similiar issue. I've created a private key with ssh-keygen and stored in a oracle table. When the client.Connect() method is being called I get the same error. I tried the key with FileZilla and the connection was established succesfully. Any help is appreciated. Thx!
Hi Any update on the above issue , I am also facing same and it is client provided key I can not modify it also.
Hi i'm having the same problem. Any update ?
Putty-key is not supported now. You may convert putty-key to openssh-key using PUTTYGEN which installed with PUTTY, and openssh-key is working well.
SSH.Net allows a format called "ssh.com". Using the PuttyGen tool, you can use the option under Conversions > Export ssh.com key
This is the only difference in the procedure to authenticate using credentials vs procedure to authenticate via private key.
Hi,
Am having the same issue if I use .ppk key for authentication. It is working fine if I convert .ppk key to OpenSSH format.
Putty key format is not supported by the library, same for the newest format OpenSSH is using
Sent from my iPhone
On Aug 9, 2019, at 9:55 AM, RaviDyapa [email protected] wrote:
Hi,
Am having the same issue if I use .ppk key for authentication. It is working fine if I convert .ppk key to OpenSSH format.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
OpenSSH format is now supported in the develop branch. For now, there's no support Putty private key files.
Can I use openssl to generate the private key?
@Rob-Hague @scott-xu I'm really excited to see that SSH.NET now supports the PuTTY private key file format. I couldn't wait to try it out, but when I tried to load my key, I got an error saying 'MAC verification failed for PuTTY key file.' It works fine with PuTTYgen, though. If this issue could be fixed, that would be awesome!
@Varorbc Would you mind sharing me a PuTTY key file that can reproduce your issue? It doesn't have to be your secret private key.
@scott-xu passphrase is 123456
PuTTY-User-Key-File-2: ssh-rsa
Encryption: aes256-cbc
Comment: rsa-key-20241203
Public-Lines: 6
AAAAB3NzaC1yc2EAAAABJQAAAQEAhtAV5j4EG1nhAMcnAjNMOjGNQ/u1xfT8G7uq
Md6tw6fJZuZt2FvFj+RsokNkYEqxeTVhEeBWG2Q/kDNuNHRDxoKchaLnlfUHJuG8
uvuxYf3khkb5ljvs095WFfjOyb59ITjhWMz+ieaYk3K81Z3zborMqbISM4jgc2/v
vu1g4+8idHCcIEYG72MAqEdy6s7n8aBGo3uQuq80iwO7WhHnTAGTRkpONWqoNntQ
YUw3zTkTcedBTyCXqwRO/Q4OB6hTX49eluMdAqK+K+46dinWpK3LLT8NdYPUA//r
i+LoQ7rGyNoDei0eTqLkPz0CsP6AjhAQ6fQBP1Rv9RsiY0BUTQ==
Private-Lines: 14
AZQvjVe9a96WgcK/jiBqY/xnt9m3HcLPDn+a0q4Fcqjf9yNdsLwwVy4TZ9hc9LSc
Y7BezoGR7tn09+uk/mUWdgG8Mzaf73vj4BoQ+kXxI77TrM85FD6W3bwj69Z2j2/p
Ii8IhPE9+AXxCi3SMUhO9xnJ9jVJtPh/YWLnmuuPjkBdEBwVfVpnTQycdRL5m1sR
52Q1P7dmHr83ZF1KSybXR/V/5nwH5mwCdcI2ZtxwulznHWO7+LTJJyBbG6ImaOa3
TLDTt4V/yPrtSP0kc5en8hKpuy+L9OliS3mKsftp2Wf4g0Pd+/qru01my/+Z58KB
Utk1f0LytMXt9ZUDdprh1YQRfnVe79Si07j/REDEdAX+3RxMm/LWsRNgnMdAflsP
YDKH6WSCx6W4LkCvEUujnSULUBdmxFkc9qVB543NOFo/Kbu+cjpyP/pKeKwFIUgm
fj1QcJ7Aevr1HemDBlJZSGe3s0CqO9+p0Bx68DDxsdXKfkxr4BWYXgd5ponHcgF/
gPxYrjJlq7NnEWS7QcQgN59TPwGKMStG4a+GZHXYC4e7bKS0MFmVZvF9xjpfsOS5
tVtQTd6N9N/r5awQfvgD8D6LLqck4Sx+tbxAfb+x6PH2CBjjYHN5qdGwt24hy34g
K/5ws8UP5h3xSbEQu7H4VoT8eDlwuaywBBGuOjbHL/HaihW09qFgc2UwpKaB2GFV
BvO65WDQAvJAxVFOJXyXUBf3MIoHDKYp0RqCTRwhGbGk730ZzqCWEqgWYvaazVsl
2OwFFATIJquMpqYFkXfdBsdNy/pkK6H4kaqJi49DHzb0zABXWCQ/i2Qqar1eAvJ5
Ly9XYW5SNUoS0dFSANdObICS7/ZRnu25f35EyDbLc+Nzzlv6yE7Bayu7KJUxwT/z
Private-MAC: 8557ad1ab24bb00aea3b5affea5e08d1e83fb184
It works in my laptop using latest develop branch. I tried both .NET Framework 4.6.2 and .NET 9.0.
@scott-xu I found that the regular expression matched the value of the comment by an extra \r, and now I have fixed it. #1550