0

I'm trying to set up an SFTP upload with an ed25519 authentication, but I keep getting this error:

Exception in thread "main" java.lang.UnsupportedOperationException: Don't know how to decode key:ssh-ed25519

This is my code:

import java.io.File;
import java.io.IOException;

import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.sftp.SFTPClient;
import net.schmizz.sshj.userauth.keyprovider.OpenSSHKeyFile;
import net.schmizz.sshj.xfer.FileSystemFile;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;

String username     = "scansionitesz"; 
String remoteDir    = "files";
String remoteFile   = "prova_delega.pdf";
String localDir     = "C:/Users/VERSIM/Desktop";

final SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(new PromiscuousVerifier());
ssh.connect(server);
try {
    File privateKey = new File(openSSHPrivateKey);
    KeyProvider keys = ssh.loadKeys(privateKey.getPath());

    OpenSSHKeyFile key = new OpenSSHKeyFile();

    key.init("-----BEGIN OPENSSH PRIVATE KEY-----\n" + 
            "my_private_key\n" + 
            "-----END OPENSSH PRIVATE KEY-----",
            "ssh-ed25519 my_public_key scansionitesz@tes" 
            );

    ssh.authPublickey(username,key);

    final SFTPClient sftp = ssh.newSFTPClient();
    try {
        sftp.put(new FileSystemFile(localDir + "/" + remoteFile), "/" + remoteDir);
    } finally {
        sftp.close();
    }
} finally {
    ssh.disconnect();
}

What am I missing?

kenny_k
  • 3,831
  • 5
  • 30
  • 41
Jon Lord
  • 3
  • 2
  • Have you verified that the format for your key ssh-ed25519 is correct? Because the error message is being quite clear that it doesn't know what todo with it. – J. Murray Oct 06 '19 at 10:42

1 Answers1

0

I guess you are using some old version of sshj that does not support the Ed25519 keys.

They are supported since 0.15.0 (November 2015).

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992