EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SSH public and private key - .Net C#

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#9816
Posted: 04/27/2009 04:08:53
by Ken Ivanov (EldoS Corp.)

Quote
however, the code piece above does not use the method LoadPublicKey. how is the public key passed to the SFTP Server then?

You do not need to use the LoadPublicKey() method. Use LoadPrivateKey() instead.

Quote
do i need to do anything else than this to pass to the SFTP
server my Public and Private keys?

No, the provided code does everything that is needed to set up client public key authentication. Why don't you try one of the demos? Each of SSH/SFTP samples illustrates the use of public key authentication. It would be much faster than waiting for obvious answers in the forum.
#9818
Posted: 04/27/2009 05:06:31
by Blue White (Basic support level)
Joined: 01/22/2009
Posts: 27

I am running SimleSftpDemo, I am trying to connect to an FTP server not SFTP server because I dont have an SFTP server and I ve been told that even it's an FTP server it should work.
( though i am not sure about this )

and I am getting an error when connecting (error 10061)

I am attaching my private key file for PUBLICKEY authentication type
my question is:
if i am not presenting my public key, then how would the SFTP server know that this private key is correct ?
(please note that the SFTP Server does not already have my public key. should i pass it my public key in other way than using .Net? )

and testing on FTP server work? knowing that the FTP server does not require public key authentication
Please note that I generated my key pair using Putty key generator, and I have put them in a folder (i am pointing to this folder in method LoadPrivateKey)
the 2 file names are as such:
privatekey.ppk
publickey

Many thanks!
#9819
Posted: 04/27/2009 05:38:16
by Ken Ivanov (EldoS Corp.)

Quote
I am running SimleSftpDemo, I am trying to connect to an FTP server not SFTP server because I dont have an SFTP server and I ve been told that even it's an FTP server it should work.( though i am not sure about this )

It will not. Please see the article regarding the differences between SFTP and FTPS protocols.

Quote
and I am getting an error when connecting (error 10061)

Just because there's no SFTP server available on remote side.

Quote
if i am not presenting my public key, then how would the SFTP server know that this private key is correct ?

A public key should be delivered to the server prior to using the corresponding private one for authentication. This can be done either by using non-SSH means (e-mail, paper mail etc.), or by using an SSH public key subsystem (the very first connection to server is authenticated using a passphrase, and all the further connections use private key authentication. A public key is uploaded to server during the first connection).
#9820
Posted: 04/27/2009 06:48:35
by Blue White (Basic support level)
Joined: 01/22/2009
Posts: 27

Thank you so much for your help, I appreciate it!
#9828
Posted: 04/27/2009 11:56:58
by Blue White (Basic support level)
Joined: 01/22/2009
Posts: 27

Hi again,

I m trying to use the SimplSftpClient sample but i am having the below error:
in connect method I have added

Code
SftpClient.Username = "usernamegoeshere";


however, I am receiving an error when running:
Object reference not set to an instance of an object

which means i have to instantiate SftpClient.Username

when looking at your sample I have realised that in the InitializeComponents() method there's a generated code:

Code
SftpClient.Username = "";


but in my code it wasnt automatically generated.

I tried to add it myself to the InitializeComponents() method. but I am getting the same error and it's pointing to InitializeComponents() method's line:
Code
SftpClient.Username = "";


do you have any idea why it wasnt automatically generated in my code and what's the right way to instantiate it.

Please note that I am now working on Windows form applicat
#9829
Posted: 04/27/2009 12:18:13
by Eugene Mayevski (EldoS Corp.)

Most likely it's SftpClient variable which is not instanciated at the moment when the assignment is made.


Sincerely yours
Eugene Mayevski
#9844
Posted: 04/28/2009 06:01:53
by Blue White (Basic support level)
Joined: 01/22/2009
Posts: 27

Hi,
yes it was the SftpClient variable which was not instantiated and it's not giving me an error anymore.

but i am facing another error now:

I am trying to run the application and im having the following error:

Unable to load DLL 'coredll.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

at line:

key.LoadPrivateKey(@"C:\Keys\privatekey.ppk","");

could you please elaborate more on this error and how to solve it?

Thanks.
#9846
Posted: 04/28/2009 08:04:15
by Blue White (Basic support level)
Joined: 01/22/2009
Posts: 27

is the code for pocket pc applications?
#9847
Posted: 04/28/2009 08:19:20
by Eugene Mayevski (EldoS Corp.)

coredll.dll is indeed a PocketPC-specific assembly. Please post the exact path to the sample that you are running. We will check if this sample is ok or some mistake sneaked into the project file.


Sincerely yours
Eugene Mayevski
#9849
Posted: 04/28/2009 08:31:33
by Blue White (Basic support level)
Joined: 01/22/2009
Posts: 27

I found out what was causing the error and it's now solved.

I did some search in the html help and found out that for desktop applications we should add the libraries under Assemblies/.Net not from Assemblies/.Net CF as i was doing
so i deleted the old references and added the new ones from Assemblies/.Net folder and the error is not occuring anymore!

Thanks :)
Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.

Reply

Statistics

Topic viewed 26317 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!