繁体   English   中英

使用 SSHJ 和 ed25519 的 SFTP 上传遇到关键问题

[英]SFTP upload using SSHJ and ed25519 experiencing key Issues

我正在尝试使用 ed25519 身份验证设置 SFTP 上传,但我不断收到此错误:

线程“主”java.lang.UnsupportedOperationException 中的异常:不知道如何解码密钥: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 月)开始支持它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM