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?
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).