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

* @throws InvalidSshKeyException
*/
    public byte[] format(AuthorizedKeys keys, AuthorizedKeysFileSaver saver)
        throws IOException, InvalidSshKeyException {
        Authorization authorization = new Authorization();
        SshPublicKeyFile pubfile;
        SECSHPublicKeyFormat secsh = new SECSHPublicKeyFormat();
        Map.Entry entry;

        for (Iterator it = keys.getAuthorizedKeys().entrySet().iterator();
                (it != null) && it.hasNext();) {
            entry = (Map.Entry) it.next();

            // Write out the public key file
            String username = (String) entry.getValue();
            String filename = username + ".pub";
            secsh.setComment(username);
            pubfile = SshPublicKeyFile.create((SshPublicKey) entry.getKey(),
                    secsh);
            saver.saveFile(filename, pubfile.toString().getBytes("US-ASCII"));

            // Write out the key entry
            authorization.addKey(filename);
        }

View Full Code Here

            Authorization authorization = new Authorization(new ByteArrayInputStream(
                        formatted));
            List keyfiles = authorization.getAuthorizedKeys();
            Iterator it = keyfiles.iterator();
            String filename;
            SshPublicKeyFile pubfile;
            String username;

            while (it.hasNext()) {
                filename = (String) it.next();
                pubfile = SshPublicKeyFile.parse(loader.loadFile(filename));
                username = filename.substring(0, filename.length() - 4);
                keys.addKey(username, pubfile.toPublicKey());
            }

            return keys;
        } catch (ParserConfigurationException ex) {
            throw new IOException("Failed to read authorization file: " +
View Full Code Here

    public byte[] format(AuthorizedKeys keys, AuthorizedKeysFileSaver saver)
        throws IOException, InvalidSshKeyException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        out.write(header.getBytes("US-ASCII"));

        SshPublicKeyFile pubfile;
        SECSHPublicKeyFormat secsh = new SECSHPublicKeyFormat();
        Map.Entry entry;

        for (Iterator it = keys.getAuthorizedKeys().entrySet().iterator();
                (it != null) && it.hasNext();) {
            entry = (Map.Entry) it.next();

            // Write out the public key file
            String username = (String) entry.getValue();
            String filename = username + ".pub";
            secsh.setComment(username);
            pubfile = SshPublicKeyFile.create((SshPublicKey) entry.getKey(),
                    secsh);
            saver.saveFile(filename, pubfile.toString().getBytes("US-ASCII"));

            // Write out the key entry
            out.write(key.getBytes("US-ASCII"));
            out.write(filename.getBytes("US-ASCII"));
            out.write('\n');
View Full Code Here

        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

* @throws InvalidSshKeyException
*/
    public byte[] format(AuthorizedKeys keys, AuthorizedKeysFileSaver saver)
        throws IOException, InvalidSshKeyException {
        Authorization authorization = new Authorization();
        SshPublicKeyFile pubfile;
        SECSHPublicKeyFormat secsh = new SECSHPublicKeyFormat();
        Map.Entry entry;

        for (Iterator it = keys.getAuthorizedKeys().entrySet().iterator();
                (it != null) && it.hasNext();) {
            entry = (Map.Entry) it.next();

            // Write out the public key file
            String username = (String) entry.getValue();
            String filename = username + ".pub";
            secsh.setComment(username);
            pubfile = SshPublicKeyFile.create((SshPublicKey) entry.getKey(),
                    secsh);
            saver.saveFile(filename, pubfile.toString().getBytes("US-ASCII"));

            // Write out the key entry
            authorization.addKey(filename);
        }

View Full Code Here

            Authorization authorization = new Authorization(new ByteArrayInputStream(
                        formatted));
            List keyfiles = authorization.getAuthorizedKeys();
            Iterator it = keyfiles.iterator();
            String filename;
            SshPublicKeyFile pubfile;
            String username;

            while (it.hasNext()) {
                filename = (String) it.next();
                pubfile = SshPublicKeyFile.parse(loader.loadFile(filename));
                username = filename.substring(0, filename.length() - 4);
                keys.addKey(username, pubfile.toPublicKey());
            }

            return keys;
        } catch (ParserConfigurationException ex) {
            throw new IOException("Failed to read authorization file: " +
View Full Code Here

    public byte[] format(AuthorizedKeys keys, AuthorizedKeysFileSaver saver)
        throws IOException, InvalidSshKeyException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        out.write(header.getBytes("US-ASCII"));

        SshPublicKeyFile pubfile;
        SECSHPublicKeyFormat secsh = new SECSHPublicKeyFormat();
        Map.Entry entry;

        for (Iterator it = keys.getAuthorizedKeys().entrySet().iterator();
                (it != null) && it.hasNext();) {
            entry = (Map.Entry) it.next();

            // Write out the public key file
            String username = (String) entry.getValue();
            String filename = username + ".pub";
            secsh.setComment(username);
            pubfile = SshPublicKeyFile.create((SshPublicKey) entry.getKey(),
                    secsh);
            saver.saveFile(filename, pubfile.toString().getBytes("US-ASCII"));

            // Write out the key entry
            out.write(key.getBytes("US-ASCII"));
            out.write(filename.getBytes("US-ASCII"));
            out.write('\n');
View Full Code Here

        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

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.