After a successful connect, one has to authenticate oneself. The authentication method "publickey" works by signing a challenge sent by the server. The signature is either DSA or RSA based - it just depends on the type of private key you specify, either a DSA or RSA private key in PEM format. And yes, this is may seem to be a little confusing, the method is called "publickey" in the SSH-2 protocol specification, however since we need to generate a signature, you actually have to supply a private key =).
The private key contained in the PEM file may also be encrypted ("Proc-Type: 4,ENCRYPTED"). The library supports DES-CBC and DES-EDE3-CBC encryption, as well as the more exotic PEM encrpytions AES-128-CBC, AES-192-CBC and AES-256-CBC.
If the authentication phase is complete, true
will be returned. If the server does not accept the request (or if further authentication steps are needed), false
is returned and one can retry either by using this or any other authentication method (use the getRemainingAuthMethods
method to get a list of the remaining possible methods).
NOTE PUTTY USERS: Event though your key file may start with "-----BEGIN..." it is not in the expected format. You have to convert it to the OpenSSH key format by using the "puttygen" tool (can be downloaded from the Putty website). Simply load your key and then use the "Conversions/Export OpenSSH key" functionality to get a proper PEM file.
@param user A String
holding the username.
@param pemPrivateKey A char[]
containing a DSA or RSA private key of the user in OpenSSH key format (PEM, you can't miss the "-----BEGIN DSA PRIVATE KEY-----" or "-----BEGIN RSA PRIVATE KEY-----" tag). The char array may contain linebreaks/linefeeds.
@param password If the PEM structure is encrypted ("Proc-Type: 4,ENCRYPTED") then you must specify a password. Otherwise, this argument will be ignored and can be set to null
.
@return whether the connection is now authenticated.
@throws IOException