PrivateKeyAuthenticationMethod

Feb 21, 2013 at 1:23 PM
Edited Feb 21, 2013 at 1:46 PM
The method takes a privateKeyFile. The PrivateKeyFile is overloaded and I'm looking at two choices. One takes just a Filename, the other takes a Filename and Passphrase.

In my program I'm allowing for a private key that does not use a passphrase. what I'm wondering is whether or not I can get by with just the second method and pass in an empty string for the passphrase when there is none?

In other words, I want to use the single constructor and hope it is smart enough to deal with a valid passphrase or an empty string. Was thinking of trying to pass null, like this:
PrivateKeyFile ppkFile = new PrivateKeyFile(@"C:\Utilities\mercury.ppk",null);
I may try to peruse the source code about this since I'm also unsure of how the PrivateKey method is utilizing the key and passphrase. It's unclear to me whether or not the target host is supposed to be receiving the ppk and passphrase separately and then does the decrypting itself, or if this is the job of the SSH client, decrypting on client machine before using in connection?

The docs don't have an example of this yet as far as I can tell.

I am also wondering if I can save the PPK text in my app and then just load that into a PrivateKeyFile. No overload seems to suggest that. I don't suppose I can substitute the string for System.IO.Stream argument. That would have been a nice fit for one of my use cases.
Coordinator
Feb 21, 2013 at 2:11 PM
Hey,

I guess what you can do is to pass second parameter as null, since empty string is a valid passphrase, and then it should work.
Also, please take a look at private key format examples, it should be in documentation and in this forum.

Hope this helps,
Thanks,
Oleg
Feb 21, 2013 at 3:21 PM
thanks, will look around and post back my experience.


From: [email removed]
To: [email removed]
Date: Thu, 21 Feb 2013 07:11:46 -0800
Subject: Re: PrivateKeyAuthenticationMethod [sshnet:433963]

From: olegkap
Hey,

I guess what you can do is to pass second parameter as null, since empty string is a valid passphrase, and then it should work.
Also, please take a look at private key format examples, it should be in documentation and in this forum.

Hope this helps,
Thanks,
Oleg
Read the full discussion online.
To add a post to this discussion, reply to this email (sshnet@discussions.codeplex.com)
To start a new discussion for this project, email sshnet@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Feb 21, 2013 at 7:10 PM
I took no chances and instead just did it in code with optional parameters, like this.
Covered all 3 of my use cases this way. Seems to work.
        private static AuthenticationMethod createAuthObject(
            string _uName,
            bool _usePrivateKey,
            string _uPassword = "",
            string _ppkPassPhrase = "",
            string _ppkPath = ""
            )
        {
            PrivateKeyFile ppkFile;
            if (_usePrivateKey)
            {
                if (_ppkPassPhrase != "")
                {
                    ppkFile = new PrivateKeyFile(_ppkPath, _ppkPassPhrase);
                }
                else
                {
                    ppkFile = new PrivateKeyFile(_ppkPath);
                }
                PrivateKeyAuthenticationMethod myAuth = new PrivateKeyAuthenticationMethod(_uName, ppkFile);
                return myAuth;
            }
            else
            {
                PasswordAuthenticationMethod myAuth = new PasswordAuthenticationMethod(_uName, _uPassword);
                return myAuth;
            }
        }