JSch: addIdentity from private key stored on hdfs [duplicate]

眉间皱痕 提交于 2019-12-18 07:07:29

问题


I need to connect to an sftp server from an hadoop cluster. I would like to know if there is a way to load an identity from a private key stored in hdfs. Actually it seems that the JSch object accepts only a local path:

try {
    String privateKeyPath = "hdfs://namenode:8020/path/to/privatekey";  // need this one to be an hdfs path
    JSch jsch = new JSch();

    jsch.addIdentity(privateKeyPath);

    // [..]
}
catch (Exception ex) {
    // [..]
}

Any idea?


回答1:


Thanks to @Martin Prikryl answer, solved as following:

// Get sftp private/public key for JSch identity
FSDataInputStream fis = fs.open(privateKeyPath);
byte[] privateKeyBytes = IOUtils.toByteArray(fis);

fis = fs.open(publicKeyPath);
byte[] publicKeyBytes = IOUtils.toByteArray(fis);
fis.close();

JSch jsch = new JSch();
String idName = "ksftp";
byte[] passphrase = null;  
jsch.addIdentity(idName, privateKeyBytes, publicKeyBytes, passphrase);


来源:https://stackoverflow.com/questions/50859100/jsch-addidentity-from-private-key-stored-on-hdfs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!