我正在尝试使用ed25519身份验证来设置SFTP上传,但我一直收到此错误:
线程“主”中的异常java.lang.UnsupportedOperationException:不知道如何解码key:ssh-ed25519
这是我的代码:
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();
}
我想念什么?
我想您使用的是不支持Ed25519键的sshj的旧版本。
自0.15.0(2015年11月)开始受支持。