Package com.sshtools.j2ssh.transport.publickey

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


        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

Related Classes of com.sshtools.j2ssh.transport.publickey.SshPublicKeyFile

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.