Examples of SshPublicKeyFile


Examples of com.sshtools.j2ssh.transport.publickey.SshPublicKeyFile

        throws IOException, InvalidSshKeyException {
        AuthorizedKeys keys = new AuthorizedKeys();
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                    new ByteArrayInputStream(formatted)));
        String line;
        SshPublicKeyFile pubfile;
        String filename;
        String username;

        while ((line = reader.readLine()) != null) {
            if (line.trim().startsWith("key")) {
                // Get the filename and load
                filename = line.substring(line.trim().lastIndexOf(" ") + 1)
                               .trim();
                pubfile = SshPublicKeyFile.parse(loader.loadFile(filename));

                // Get the username from the filename - .pub
                username = filename.substring(0, filename.length() - 4);
                keys.addKey(username, pubfile.toPublicKey());
            }
        }

        return keys;
    }
View Full Code Here

Examples of com.sshtools.j2ssh.transport.publickey.SshPublicKeyFile

* @throws InvalidSshKeyException
*/
    public byte[] format(AuthorizedKeys keys)
        throws IOException, InvalidSshKeyException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        SshPublicKeyFile pubfile;
        OpenSSHPublicKeyFormat openssh = new OpenSSHPublicKeyFormat();
        Map.Entry entry;

        for (Iterator it = keys.getAuthorizedKeys().entrySet().iterator();
                (it != null) && it.hasNext();) {
            entry = (Map.Entry) it.next();
            openssh.setComment((String) entry.getValue());
            pubfile = SshPublicKeyFile.create((SshPublicKey) entry.getKey(),
                    openssh);
            out.write(pubfile.toString().getBytes("US-ASCII"));
            out.write('\n');
        }

        return out.toByteArray();
    }
View Full Code Here

Examples of com.sshtools.j2ssh.transport.publickey.SshPublicKeyFile

        throws IOException, InvalidSshKeyException {
        AuthorizedKeys keys = new AuthorizedKeys();
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                    new ByteArrayInputStream(formatted)));
        String line;
        SshPublicKeyFile pubfile;

        while ((line = reader.readLine()) != null) {
            pubfile = SshPublicKeyFile.parse(line.getBytes("US-ASCII"));
            keys.addKey(pubfile.getComment(), pubfile.toPublicKey());
        }

        return keys;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.