Package com.sshtools.j2ssh.util

Examples of com.sshtools.j2ssh.util.SimpleASNWriter


            }

            // Using a SimpleASNWriter
            ByteArrayOutputStream r = new ByteArrayOutputStream();
            ByteArrayOutputStream s = new ByteArrayOutputStream();
            SimpleASNWriter asn = new SimpleASNWriter();
            asn.writeByte(0x02);

            if (((signature[0] & 0x80) == 0x80) && (signature[0] != 0x00)) {
                r.write(0);
                r.write(signature, 0, 20);
            } else {
                r.write(signature, 0, 20);
            }

            asn.writeData(r.toByteArray());
            asn.writeByte(0x02);

            if (((signature[20] & 0x80) == 0x80) && (signature[20] != 0x00)) {
                s.write(0);
                s.write(signature, 20, 20);
            } else {
                s.write(signature, 20, 20);
            }

            asn.writeData(s.toByteArray());

            SimpleASNWriter asnEncoded = new SimpleASNWriter();
            asnEncoded.writeByte(0x30);
            asnEncoded.writeData(asn.toByteArray());

            byte[] encoded = asnEncoded.toByteArray();

            if (log.isDebugEnabled()) {
                log.debug("Verifying host key signature");
                log.debug("Signature length is " +
                    String.valueOf(signature.length));
View Full Code Here


     */
    public static void writeDSAKeyInfo(SimpleASNWriter asn, DSAKeyInfo keyInfo) {
        // Write to a substream temporarily.
        // This code needs to know the length of the substream before it can write the data from
        // the substream to the main stream.
        SimpleASNWriter asn2 = new SimpleASNWriter();
        asn2.writeByte(0x02); // INTEGER (version)

        byte[] version = new byte[1];
        asn2.writeData(version);
        asn2.writeByte(0x02); // INTEGER (p)
        asn2.writeData(keyInfo.getP().toByteArray());
        asn2.writeByte(0x02); // INTEGER (q)
        asn2.writeData(keyInfo.getQ().toByteArray());
        asn2.writeByte(0x02); // INTEGER (g)
        asn2.writeData(keyInfo.getG().toByteArray());
        asn2.writeByte(0x02); // INTEGER (y)
        asn2.writeData(keyInfo.getY().toByteArray());
        asn2.writeByte(0x02); // INTEGER (x)
        asn2.writeData(keyInfo.getX().toByteArray());

        byte[] dsaKeyEncoded = asn2.toByteArray();
        asn.writeByte(0x30); // SEQUENCE
        asn.writeData(dsaKeyEncoded);
    }
View Full Code Here

                BigInteger p = bar.readBigInteger();
                BigInteger q = bar.readBigInteger();
                BigInteger g = bar.readBigInteger();
                BigInteger x = bar.readBigInteger();
                DSAKeyInfo keyInfo = new DSAKeyInfo(p, q, g, x, BigInteger.ZERO);
                SimpleASNWriter asn = new SimpleASNWriter();
                DSAKeyInfo.writeDSAKeyInfo(asn, keyInfo);
                payload = asn.toByteArray();
                pem.setType(PEM.DSA_PRIVATE_KEY);
            } else if ("ssh-rsa".equals(algorithm)) {
                BigInteger e = bar.readBigInteger();
                BigInteger n = bar.readBigInteger();
                BigInteger p = bar.readBigInteger();
                RSAKeyInfo keyInfo = new RSAKeyInfo(n, p, e, BigInteger.ZERO,
                        BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO,
                        BigInteger.ZERO);
                SimpleASNWriter asn = new SimpleASNWriter();
                RSAKeyInfo.writeRSAKeyInfo(asn, keyInfo);
                payload = asn.toByteArray();
                pem.setType(PEM.RSA_PRIVATE_KEY);
            } else {
                throw new InvalidSshKeyException(
                    "Unsupported J2SSH algorithm: " + algorithm);
            }
View Full Code Here

     */
    public static void writeRSAKeyInfo(SimpleASNWriter asn, RSAKeyInfo keyInfo) {
        // Write to a substream temporarily.
        // This code needs to know the length of the substream before it can write the data from
        // the substream to the main stream.
        SimpleASNWriter asn2 = new SimpleASNWriter();
        asn2.writeByte(0x02); // INTEGER (version)

        byte[] version = new byte[1];
        asn2.writeData(version);
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getModulus().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getPublicExponent().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getPrivateExponent().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getPrimeP().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getPrimeQ().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getPrimeExponentP().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getPrimeExponentQ().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getCrtCoefficient().toByteArray());

        byte[] rsaKeyEncoded = asn2.toByteArray();
        asn.writeByte(0x30); // SEQUENCE
        asn.writeData(rsaKeyEncoded);
    }
View Full Code Here

            }

            // Using a SimpleASNWriter
            ByteArrayOutputStream r = new ByteArrayOutputStream();
            ByteArrayOutputStream s = new ByteArrayOutputStream();
            SimpleASNWriter asn = new SimpleASNWriter();
            asn.writeByte(0x02);

            if (((signature[0] & 0x80) == 0x80) && (signature[0] != 0x00)) {
                r.write(0);
                r.write(signature, 0, 20);
            } else {
                r.write(signature, 0, 20);
            }

            asn.writeData(r.toByteArray());
            asn.writeByte(0x02);

            if (((signature[20] & 0x80) == 0x80) && (signature[20] != 0x00)) {
                s.write(0);
                s.write(signature, 20, 20);
            } else {
                s.write(signature, 20, 20);
            }

            asn.writeData(s.toByteArray());

            SimpleASNWriter asnEncoded = new SimpleASNWriter();
            asnEncoded.writeByte(0x30);
            asnEncoded.writeData(asn.toByteArray());

            byte[] encoded = asnEncoded.toByteArray();

            if (log.isDebugEnabled()) {
                log.debug("Verifying host key signature");
                log.debug("Signature length is " +
                    String.valueOf(signature.length));
View Full Code Here

     */
    public static void writeRSAKeyInfo(SimpleASNWriter asn, RSAKeyInfo keyInfo) {
        // Write to a substream temporarily.
        // This code needs to know the length of the substream before it can write the data from
        // the substream to the main stream.
        SimpleASNWriter asn2 = new SimpleASNWriter();
        asn2.writeByte(0x02); // INTEGER (version)

        byte[] version = new byte[1];
        asn2.writeData(version);
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getModulus().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getPublicExponent().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getPrivateExponent().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getPrimeP().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getPrimeQ().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getPrimeExponentP().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getPrimeExponentQ().toByteArray());
        asn2.writeByte(0x02); // INTEGER ()
        asn2.writeData(keyInfo.getCrtCoefficient().toByteArray());

        byte[] rsaKeyEncoded = asn2.toByteArray();
        asn.writeByte(0x30); // SEQUENCE
        asn.writeData(rsaKeyEncoded);
    }
View Full Code Here

                BigInteger p = bar.readBigInteger();
                BigInteger q = bar.readBigInteger();
                BigInteger g = bar.readBigInteger();
                BigInteger x = bar.readBigInteger();
                DSAKeyInfo keyInfo = new DSAKeyInfo(p, q, g, x, BigInteger.ZERO);
                SimpleASNWriter asn = new SimpleASNWriter();
                DSAKeyInfo.writeDSAKeyInfo(asn, keyInfo);
                payload = asn.toByteArray();
                pem.setType(PEM.DSA_PRIVATE_KEY);
            } else if ("ssh-rsa".equals(algorithm)) {
                BigInteger e = bar.readBigInteger();
                BigInteger n = bar.readBigInteger();
                BigInteger p = bar.readBigInteger();
                RSAKeyInfo keyInfo = new RSAKeyInfo(n, p, e, BigInteger.ZERO,
                        BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO,
                        BigInteger.ZERO);
                SimpleASNWriter asn = new SimpleASNWriter();
                RSAKeyInfo.writeRSAKeyInfo(asn, keyInfo);
                payload = asn.toByteArray();
                pem.setType(PEM.RSA_PRIVATE_KEY);
            } else {
                throw new InvalidSshKeyException(
                    "Unsupported J2SSH algorithm: " + algorithm);
            }
View Full Code Here

     */
    public static void writeDSAKeyInfo(SimpleASNWriter asn, DSAKeyInfo keyInfo) {
        // Write to a substream temporarily.
        // This code needs to know the length of the substream before it can write the data from
        // the substream to the main stream.
        SimpleASNWriter asn2 = new SimpleASNWriter();
        asn2.writeByte(0x02); // INTEGER (version)

        byte[] version = new byte[1];
        asn2.writeData(version);
        asn2.writeByte(0x02); // INTEGER (p)
        asn2.writeData(keyInfo.getP().toByteArray());
        asn2.writeByte(0x02); // INTEGER (q)
        asn2.writeData(keyInfo.getQ().toByteArray());
        asn2.writeByte(0x02); // INTEGER (g)
        asn2.writeData(keyInfo.getG().toByteArray());
        asn2.writeByte(0x02); // INTEGER (y)
        asn2.writeData(keyInfo.getY().toByteArray());
        asn2.writeByte(0x02); // INTEGER (x)
        asn2.writeData(keyInfo.getX().toByteArray());

        byte[] dsaKeyEncoded = asn2.toByteArray();
        asn.writeByte(0x30); // SEQUENCE
        asn.writeData(dsaKeyEncoded);
    }
View Full Code Here

TOP

Related Classes of com.sshtools.j2ssh.util.SimpleASNWriter

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.