Public Key Authentication

Help
2009-12-07
2013-05-20
  • Jose Velasquez
    Jose Velasquez
    2009-12-07

    Hello

    I'm trying to connect to FTP SSH server, the authentication is using a public key, but when I send the setKeyfile, it says: com.sshtools.j2ssh.authentication.AuthenticationProtocolException: You must supply a username and a key.

    this is my code:

    /**************************************************************/

    PublicKeyAuthenticationClient pk = new PublicKeyAuthenticationClient();

    pk.setUsername("user");

    SshPublicKeyFile file1 =  SshPublicKeyFile.parse(new File("C:/HostKeys/prueba.pub"));

    SshPublicKey key = file1.toPublicKey();

    pk.setKeyfile(key.toString());

    int result = ssh.authenticate(pk);

    /**************************************************************/

    Can help me please.

    Best regards.

     
  • Pat
    Pat
    2009-12-07

    SshPrivateKeyFile keyFile = SshPrivateKeyFile.parse(privateKey);
    SshPrivateKeyFile key = keyFile.toPrivateKey(privateKeyPassword);
    pk.setKey(key);

     
  • Jose Velasquez
    Jose Velasquez
    2009-12-07

    Hello, thanks a lot for your response.

    It code works fine, but when I'm trying to pass the public file "prueba.pub", it says:
    com.sshtools.j2ssh.transport.publickey.InvalidSshKeyException: The key format is not a supported format.

    The PrivateKey is ok, but how can I implement PublicKey?, and What is the String that I need send to pk.setKeyfile("String"); ?

    Thanks in advance.

     
  • Pat
    Pat
    2009-12-07

    You need to use the private key. The server uses the public key.

     
  • Jose Velasquez
    Jose Velasquez
    2009-12-07

    ok Thanks a lot , I appreciate very much your response.