Package com.sshtools.j2ssh.io

Examples of com.sshtools.j2ssh.io.ByteArrayWriter


     *
     * @return
     */
    public byte[] encryptKeyblob(byte[] keyblob, String passphrase) {
        try {
            ByteArrayWriter baw = new ByteArrayWriter();
            String type = "none";

            if (passphrase != null) {
                if (!passphrase.trim().equals("")) {
                    // Encrypt the data
                    type = "3DES-CBC";

                    // Decrypt the key
                    byte[] keydata = makePassphraseKey(passphrase);
                    byte[] iv = new byte[8];
                    ConfigurationLoader.getRND().nextBytes(iv);

                    Cipher cipher = Cipher.getInstance(
                            "DESede/CBC/PKCS5Padding");
                    KeySpec keyspec = new DESedeKeySpec(keydata);
                    Key key = SecretKeyFactory.getInstance("DESede")
                                              .generateSecret(keyspec);
                    cipher.init(Cipher.ENCRYPT_MODE, key,
                        new IvParameterSpec(iv, 0, cipher.getBlockSize()));

                    ByteArrayWriter data = new ByteArrayWriter();
                    baw.writeString(type);
                    baw.write(iv);
                    data.writeInt(cookie);
                    data.writeBinaryString(keyblob);

                    // Encrypt and write
                    baw.writeBinaryString(cipher.doFinal(data.toByteArray()));

                    return formatKey(baw.toByteArray());
                }
            }

View Full Code Here


     *
     * @return
     */
    public byte[] getEncoded() {
        try {
            ByteArrayWriter baw = new ByteArrayWriter();
            baw.writeString(getAlgorithmName());
            baw.writeBigInteger(pubkey.getParams().getP());
            baw.writeBigInteger(pubkey.getParams().getQ());
            baw.writeBigInteger(pubkey.getParams().getG());
            baw.writeBigInteger(pubkey.getY());

            return baw.toByteArray();
        } catch (IOException ioe) {
            return null;
        }
    }
View Full Code Here

     *
     * @return
     */
    public byte[] getEncoded() {
        try {
            ByteArrayWriter baw = new ByteArrayWriter();
            baw.writeString("ssh-dss");
            baw.writeBigInteger(prvkey.getParams().getP());
            baw.writeBigInteger(prvkey.getParams().getQ());
            baw.writeBigInteger(prvkey.getParams().getG());
            baw.writeBigInteger(prvkey.getX());

            return baw.toByteArray();
        } catch (IOException ioe) {
            return null;
        }
    }
View Full Code Here

                }

                log.debug("SSH signature is " + str);
            }

            ByteArrayWriter baw = new ByteArrayWriter();
            baw.writeString(getAlgorithmName());
            baw.writeBinaryString(decoded);

            return baw.toByteArray();
        } catch (Exception e) {
            throw new InvalidSshKeySignatureException(e);
        }
    }
View Full Code Here

     *
     * @throws InvalidMessageException
     */
    public byte[] toByteArray() throws InvalidMessageException {
        try {
            ByteArrayWriter baw = new ByteArrayWriter();
            baw.write(type);
            constructByteArray(baw);

            return baw.toByteArray();
        } catch (IOException ioe) {
            throw new InvalidMessageException(
                "The message data cannot be written!");
        }
    }
View Full Code Here

    private void collectNextMessage() throws IOException {
        SubsystemMessage msg = messageStore.nextMessage();

        try {
            ByteArrayWriter baw = new ByteArrayWriter();
            byte[] data = msg.toByteArray();
            baw.writeInt(data.length);
            baw.write(data);
            msgdata = baw.toByteArray();
        } catch (InvalidMessageException ime) {
            throw new IOException(
                "An invalid message was encountered in the inputstream");
        }
View Full Code Here

    public boolean setEnvironmentVariable(String name, String value)
        throws IOException {
        log.debug("Requesting environment variable to be set [" + name + "=" +
            value + "]");

        ByteArrayWriter baw = new ByteArrayWriter();
        baw.writeString(name);
        baw.writeString(value);

        return connection.sendChannelRequest(this, "env", true,
            baw.toByteArray());
    }
View Full Code Here

    public boolean requestX11Forwarding(int display, String cookie)
        throws IOException {
        log.debug("Requesting X11 forwarding for display " + display +
            " using cookie " + cookie);

        ByteArrayWriter baw = new ByteArrayWriter();
        baw.writeBoolean(false);
        baw.writeString("MIT-MAGIC-COOKIE-1");
        baw.writeString(cookie);
        baw.writeUINT32(new UnsignedInteger32(String.valueOf(display)));

        return connection.sendChannelRequest(this, "x11-req", true,
            baw.toByteArray());
    }
View Full Code Here

     */
    public void changeTerminalDimensions(PseudoTerminal term)
        throws IOException {
        log.debug("Changing terminal dimensions");

        ByteArrayWriter baw = new ByteArrayWriter();
        baw.writeInt(term.getColumns());
        baw.writeInt(term.getRows());
        baw.writeInt(term.getWidth());
        baw.writeInt(term.getHeight());
        connection.sendChannelRequest(this, "window-change", false,
            baw.toByteArray());
    }
View Full Code Here

     */
    public boolean executeCommand(String command) throws IOException {
        log.info("Requesting command execution");
        log.debug("Command is " + command);

        ByteArrayWriter baw = new ByteArrayWriter();
        baw.writeString(command);

        if (connection.sendChannelRequest(this, "exec", true, baw.toByteArray())) {
            if (sessionType.equals("Uninitialized")) {
                sessionType = command;
            }

            return true;
View Full Code Here

TOP

Related Classes of com.sshtools.j2ssh.io.ByteArrayWriter

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.