JSch:从存储在hdfs上的私钥获取addIdentity

编程入门 行业动态 更新时间:2024-10-25 12:28:59
本文介绍了JSch:从存储在hdfs上的私钥获取addIdentity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

有什么主意吗?

推荐答案

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

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

更多推荐

JSch:从存储在hdfs上的私钥获取addIdentity

本文发布于:2023-11-05 06:13:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560117.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:JSch   hdfs   addIdentity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!