JSch:存储在hdfs上的私钥的addIdentity

我需要从hadoop集群连接到sftp服务器。 我想知道是否有办法从存储在hdfs中的私钥加载身份。 实际上似乎JSch对象只接受本地路径:

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) { // [..] } 

任何想法?

感谢@Martin Prikryl的回答,解决如下:

 // 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);