Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# getting "DER length is '95' and cannot be more than 4 bytes" error while using SSH Ftp

Tags:

c#

ssh

ftp

Code:

var connectionInfo = new ConnectionInfo(Utilities.GetConfigValueByKey(processName + Constants.KEY_FTP_SERVER), Convert.ToInt32(Utilities.GetConfigValueByKey(processName + Constants.KEY_FTP_PORT)),
                Utilities.GetConfigValueByKey(processName + Constants.KEY_FTP_USERID),
                new PasswordAuthenticationMethod(Utilities.GetConfigValueByKey(processName + Constants.KEY_FTP_USERID)
                                               , Utilities.GetConfigValueByKey(processName + Constants.KEY_FTP_PWD)),
                new PrivateKeyAuthenticationMethod(Utilities.GetConfigValueByKey(processName + Constants.KEY_FTP_USERID),
                     new PrivateKeyFile(File.OpenRead(@"C:\Jobs\Test\id_rsa"), "testpwd"))
            );

It fails at the privateKeyfile, can someone help me what is that I am doing wrong.

I have tried the filename as a text file but still no luck.

like image 463
Anjan Medicherla Avatar asked Mar 25 '26 23:03

Anjan Medicherla


1 Answers

For the history and if could help someone. The issue for me was with the passphrase. Had an extra character (carriage return) and it makes brake the key access and show this error

like image 81
user2453823 Avatar answered Mar 28 '26 11:03

user2453823



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!