Package com.davfx.ninio.ssh

Examples of com.davfx.ninio.ssh.SshPacket


  public PublicKeyLoader(File file) throws IOException, GeneralSecurityException {
    try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8))) {
      List<String> l = Splitter.on(' ').splitToList(r.readLine());
      String publicKeyAlgorithm = l.get(0);
      byte[] b = BaseEncoding.base64().decode(l.get(1));
      SshPacket k = new SshPacket(ByteBuffer.wrap(b));
      String s = k.readString();
      if (!s.equals(publicKeyAlgorithm)) {
        throw new IOException("Invalid algorithm: " + s);
      }
      if (publicKeyAlgorithm.equals("ssh-rsa")) {
        byte[] e = k.readBlob();
        byte[] n = k.readBlob();
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        publicKey = new RsaSshPublicKey((RSAPublicKey) keyFactory.generatePublic(new RSAPublicKeySpec(new BigInteger(n), new BigInteger(e))));
      } else if (publicKeyAlgorithm.equals("ssh-dss")) {
        byte[] p = k.readBlob();
        byte[] q = k.readBlob();
        byte[] g = k.readBlob();
        byte[] y = k.readBlob();

        KeyFactory keyFactory = KeyFactory.getInstance("DSA");
        publicKey = new DssSshPublicKey((DSAPublicKey) keyFactory.generatePublic(new DSAPublicKeySpec(new BigInteger(y), new BigInteger(p), new BigInteger(q), new BigInteger(g))));
      } else {
        throw new IOException("Unknown algorithm: " + publicKeyAlgorithm);
View Full Code Here

TOP

Related Classes of com.davfx.ninio.ssh.SshPacket

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.