The PrivateKey property is used when you want to
authenticate with the server using your private/public key
pair, instead of using Password. This is a
feature that should be supported by all SSH servers.
The Idea of using keys is this: you own a private key (and no one else knows this value). You supply
the server with the public key that
corresponds to your private key. Once you initiate a
connection, wodSSH will request publickey authentication.
The server will check its internal list of public keys (usually
stored in -/.ssh/authorized_keys2
or -/.ssh2/authorized files). If a
match is found, it will send a request to wodSSH to prove you
own the private key. Internally, wodSSH will sign some data
using the key you provided, and the server will check the
signature. If they match, it will allow you to login. Some
servers will also require you to enter a password, in which
case this make the server even more secure.
To generate a PrivateKey that you can use with the server, use the
Keys object (included in setup package) like this (VB
Dim key As New
key.Generate RSAkey ' 1024 bits is
key.Save RSAkey, "C:\my_rsa_key.txt", "My secret password"
The above sample will generate your private key and store it
to file on disk, protected with a password. You
can immediately continue your code like this:
Ssh1.Login = "johndoe"
Ssh1.PrivateKey = key ' or also
Ssh1.PrivateKey = key.PrivateKey(RSAkey)
Ssh1.Authentication = authPubkey
Since generation of keys may be a lengthy process (for
large bit numbers it can take a few seconds), you
shouldn't generate it every time you need to use it.
Rather, since it was saved, you should try to load it from
disk. A typical scenario would be :
Dim key As New WODSSHKeyLib.Keys
On Error Resume
' try to load previously saved
key.Load "C:\my_rsa_key.txt", "My secret password"
If Err <> 0 Then 'key was not saved
RSAkey ' 1024 bits is
RSAkey, "C:\my_rsa_key.txt", "My secret password"
' next time you run this code it will be able to load
it from the disk,
' so expensive Generate will not be called
Now that you have your PrivateKey created, you should
let the server know about it. You should do this by pasting the
public key to the appropriate files
on the server. For SSH servers (version 2), these are
should have a line of text Key
somefile.pub in a separate line of the file,
-/.ssh2/somefile.pub which should
contain your public key, as
returned by Keys.PublicKeySSH property.
For OpenSSH servers, you should paste the contents of
-/.ssh/authorized_keys2 as a new
line in the file.
For VC users, you can prepare a returned key (loaded from
file, for example) by converting it to SAFEARRAY like
(Buffer holds key data, and Bufsize holds key length)
char HUGEP *data;
SafeArrayAccessData(psa, (void HUGEP*
var.vt =VT_ARRAY | VT_UI1;
and now you can pass this VARIANT to the PrivateKey
property. Or, you can pass LPDISPATCH from the IKeys object
directly in the same way:
var.vt = VT_DISPATCH;
var.pdispVal = (LPDISPATCH)your_keys_object_instance
and it will work too.