Page 1 of 1

SSH key as resource

Posted: Sat 23 Jan 2010 03:35
by JimBalo
Hello,

I am trying to specify the SSH PrivateKey as an "compiled resource" following http://www.devart.com/dotconnect/mysql/ ... tions.html, but I keep getting an exception that it cannot find the resource.

I have tried every which way. I have added the key file as an "embedded resource" (by the Build Action property) and I have also tried putting the key in resources.resx, but nothing seems to work. Of course I set PrivateKey = "resource://whatever.key" The solution is multi-project WinForm app. Does the resource go in the output project, or in the data access layer project??

Could you please post a simple C# sample project with an SSH key as a compiled resource with a short snippet that uses it?

Cheers!
Jim

Posted: Mon 25 Jan 2010 16:48
by StanislavK
To use the SSH private key as a compiled resource, you may perform the following:

1. Add the client.key file containing the private key to the root of your DAL project.
2. Set the "Embedded resource" compile option for this file.
3. Specify the file's name in MySqlConnection.SshOptions:

Code: Select all

mySqlConnection1.SshOptions.PrivateKey = "resource://client.key";
I send a sample project to the email you've provided in your forum profile. Please check that the letter is not blocked by your mail filter.

Also, please check that you are able to connect to your SSH server using some standard tool.

Posted: Tue 26 Jan 2010 13:34
by Shalex
Also try adding your project name before the name of your private key:

Code: Select all

mySqlConnection1.SshOptions.PrivateKey = "resource://MyProject.client.key";

Posted: Wed 27 Jan 2010 02:02
by JimBalo
Hello,

I tried the attached sample, and it works with that. It also works with any project I create from scratch. But for some reason it does not work with the existing app I tried with. So I stripped that app down to a very simple sample and emailed it to you so that you can check it out.

I use the exact same connection string and key that I use in the working sample, but for some reason it "Cannot connect to server" in the solution I emailed you. Very peculiar.

Please check out and let me know.

Cheers!
Jim

Posted: Wed 27 Jan 2010 12:46
by StanislavK
We will investigate the problem and inform you about the results.

Posted: Tue 02 Feb 2010 15:39
by JimBalo
Please give status on this.

Thanks,
Jim

Posted: Tue 02 Feb 2010 16:14
by StanislavK
The correct format of the resource identifier is

Code: Select all

resource://MyAssembly,%ResourcePath%
where MyAssembly stands for the assembly into which the resource is embedded, and ResourcePath is the complete path to the resource in the project. To determine the assembly name you can, e.g., check the "Assembly Name" field in the properties of the project containing the resource.

For example, in the project you've sent us the resource identifier for the private key should be

Code: Select all

resource://BusinessLayer,client.key

Posted: Wed 03 Feb 2010 02:12
by JimBalo
That works. Maybe something you could put in your documentation?

Also, and pardon my ignorance, I noticed that the key as a resource is visible in plain text in the compiled assembly. I noticed another post about adding a property for providing the key as a string instead. This would work much better for me. Having the private key in plain view kind of defeats the purpose of using SSH in the first place. But I'll add a post to that thread asking for ETA, etc.

Cheers!
Jim

Posted: Wed 03 Feb 2010 10:41
by StanislavK
Thank you for your suggestions. We will add the information about the resource identifier format to the documentation.