栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

私钥/公钥认证的ssh示例

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

私钥/公钥认证的ssh示例

尝试KeyPairWrapper像这样使用:

KeyPair kp = ... // read keypair from filessh.authPublickey(user, new KeyPairWrapper(keypair));

使用BouncyCastle提供程序,您可以使用类似的方法从PKCS8 PEM(为混乱的代码道歉)中提取KeyPair。

public static KeyPair readKeypair(final InputStream is, final char[] password) throws IOException {    PasswordFinder passwordFinder = password != null ? new StaticPasswordFinder(password) : null;    KeyPair kp = null;    try {        // read the stream as a PEM enpred        try { final PEMReader pem = new PEMReader(new InputStreamReader(is), passwordFinder); try {     // Skip over entries in the file which are not KeyPairs     do {         final Object o = pem.readObject();         if (o == null)  break; // at end of file         else if (o instanceof KeyPair)  kp = (KeyPair) o;     } while (kp == null); } finally {     pem.close(); }        }        catch (EncryptionException e) { throw new IOException("Error reading PEM stream: " + e.getMessage(), e);        }    }    finally {        is.close();    }    // Cast the return to a KeyPair (or, if there is no [valid] return, throw an exception)    if (kp != null)        return kp;    else        throw new IOException("Stream " + is + " did not contain a PKCS8 KeyPair");}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/455102.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号