Examples of ArmoredInputStream


Examples of org.bouncycastle.bcpg.ArmoredInputStream

        InputStream        in,
        InputStream        keyIn,
        String             resultName)
        throws Exception
    {
        ArmoredInputStream    aIn = new ArmoredInputStream(in);
        OutputStream          out = new BufferedOutputStream(new FileOutputStream(resultName));



        //
        // write out signed section using the local line separator.
        // note: although we leave it in trailing white space as it is not verifiable.
        // Some people prefer to remove it.
        //
        ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
        int                   lookAhead = readInputLine(lineOut, aIn);
        byte[]                lineSep = getLineSeparator();

        if (lookAhead != -1 && aIn.isClearText())
        {
            byte[] line = lineOut.toByteArray();
            out.write(line, 0, getLengthWithoutSeparator(line));
            out.write(lineSep);

            while (lookAhead != -1 && aIn.isClearText())
            {
                lookAhead = readInputLine(lineOut, lookAhead, aIn);
               
                line = lineOut.toByteArray();
                out.write(line, 0, getLengthWithoutSeparator(line));
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredInputStream

        {
            if (!isPossiblyBase64(ch))
            {
                in.reset();
       
                return new ArmoredInputStream(in);
            }
           
            byte[]  buf = new byte[READ_AHEAD];
            int     count = 1;
            int     index = 1;
           
            buf[0] = (byte)ch;
            while (count != READ_AHEAD && (ch = in.read()) >= 0)
            {
                if (!isPossiblyBase64(ch))
                {
                    in.reset();
                   
                    return new ArmoredInputStream(in);
                }
               
                if (ch != '\n' && ch != '\r')
                {
                    buf[index++] = (byte)ch;
                }
               
                count++;
            }
           
            in.reset();
       
            //
            // nothing but new lines, little else, assume regular armoring
            //
            if (count < 4)
            {
                return new ArmoredInputStream(in);
            }
           
            //
            // test our non-blank data
            //
            byte[]    firstBlock = new byte[8];
           
            System.arraycopy(buf, 0, firstBlock, 0, firstBlock.length);

            byte[]    decoded = Base64.decode(firstBlock);
           
            //
            // it's a base64 PGP block.
            //
            if ((decoded[0] & 0x80) != 0)
            {
                return new ArmoredInputStream(in, false);
            }
           
            return new ArmoredInputStream(in);
        }
    }
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredInputStream

    private void blankLineTest() throws Exception
    {
        byte[] blankLineBytes = Strings.toByteArray(blankLineData);
        ByteArrayInputStream bIn = new ByteArrayInputStream(blankLineBytes);
        ArmoredInputStream aIn = new ArmoredInputStream(bIn, true);

        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        int c;
        while ((c = aIn.read()) >= 0)
        {
            bOut.write(c);
        }

        byte[] expected = Strings.toByteArray("Hello World!");
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredInputStream

        aOut.write(sample);

        aOut.close();

        ArmoredInputStream aIn = new ArmoredInputStream(new ByteArrayInputStream(bOut.toByteArray()));

        PGPObjectFactory fact = new PGPObjectFactory(aIn);
        int count = 0;

        while (fact.nextObject() != null)
        {
            count++;
        }

        if (count != 1)
        {
            fail("wrong number of objects found: " + count);
        }

        //
        // writing and reading multiple objects  - in single block
        //
        bOut = new ByteArrayOutputStream();
        aOut = new ArmoredOutputStream(bOut);

        aOut.write(sample);
        aOut.write(sample);

        aOut.close();

        aIn = new ArmoredInputStream(new ByteArrayInputStream(bOut.toByteArray()));

        fact = new PGPObjectFactory(aIn);
        count = 0;

        while (fact.nextObject() != null)
        {
            count++;
        }

        if (count != 2)
        {
            fail("wrong number of objects found: " + count);
        }

        //
        // writing and reading multiple objects  - in single block
        //
        bOut = new ByteArrayOutputStream();
        aOut = new ArmoredOutputStream(bOut);

        aOut.write(sample);

        aOut.close();     // does not close underlying stream

        aOut = new ArmoredOutputStream(bOut);

        aOut.write(sample);

        aOut.close();

        aIn = new ArmoredInputStream(new ByteArrayInputStream(bOut.toByteArray()));

        count = 0;
        boolean atLeastOne;
        do
        {
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredInputStream

        {
            if (!isPossiblyBase64(ch))
            {
                in.reset();
       
                return new ArmoredInputStream(in);
            }
           
            byte[]  buf = new byte[READ_AHEAD];
            int     count = 1;
            int     index = 1;
           
            buf[0] = (byte)ch;
            while (count != READ_AHEAD && (ch = in.read()) >= 0)
            {
                if (!isPossiblyBase64(ch))
                {
                    in.reset();
                   
                    return new ArmoredInputStream(in);
                }
               
                if (ch != '\n' && ch != '\r')
                {
                    buf[index++] = (byte)ch;
                }
               
                count++;
            }
           
            in.reset();
       
            //
            // nothing but new lines, little else, assume regular armoring
            //
            if (count < 4)
            {
                return new ArmoredInputStream(in);
            }
           
            //
            // test our non-blank data
            //
            byte[]    firstBlock = new byte[8];
           
            System.arraycopy(buf, 0, firstBlock, 0, firstBlock.length);

            byte[]    decoded = Base64.decode(firstBlock);
           
            //
            // it's a base64 PGP block.
            //
            if ((decoded[0] & 0x80) != 0)
            {
                return new ArmoredInputStream(in, false);
            }
           
            return new ArmoredInputStream(in);
        }
    }
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredInputStream

        InputStream        in,
        InputStream        keyIn,
        String             resultName)
        throws Exception
    {
        ArmoredInputStream    aIn = new ArmoredInputStream(in);
        OutputStream          out = new BufferedOutputStream(new FileOutputStream(resultName));



        //
        // write out signed section using the local line separator.
        // note: trailing white space needs to be removed from the end of
        // each line RFC 4880 Section 7.1
        //
        ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
        int                   lookAhead = readInputLine(lineOut, aIn);
        byte[]                lineSep = getLineSeparator();

        if (lookAhead != -1 && aIn.isClearText())
        {
            byte[] line = lineOut.toByteArray();
            out.write(line, 0, getLengthWithoutSeparatorOrTrailingWhitespace(line));
            out.write(lineSep);

            while (lookAhead != -1 && aIn.isClearText())
            {
                lookAhead = readInputLine(lineOut, lookAhead, aIn);
               
                line = lineOut.toByteArray();
                out.write(line, 0, getLengthWithoutSeparatorOrTrailingWhitespace(line));
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredInputStream

    private void messageTest(
        String message,
        String type)
        throws Exception
    {
        ArmoredInputStream aIn = new ArmoredInputStream(new ByteArrayInputStream(message.getBytes()));

        String[] headers = aIn.getArmorHeaders();
       
        if (headers == null || headers.length != 1)
        {
            fail("wrong number of headers found");
        }
       
        if (!"Hash: SHA256".equals(headers[0]))
        {
            fail("header value wrong: " + headers[0]);
        }
       
        //
        // read the input, making sure we ingore the last newline.
        //
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        int                   ch;

        while ((ch = aIn.read()) >= 0 && aIn.isClearText())
        {
            bOut.write((byte)ch);
        }

        PGPPublicKeyRingCollection pgpRings = new PGPPublicKeyRingCollection(publicKey);
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredInputStream

        PGPPublicKey publicKey = null;
        PGPSignature pgpSignature = null;

        try {
            if (!(signature instanceof ArmoredInputStream)) {
                signature = new ArmoredInputStream(signature);
            }

            pgpSignature = isSignatureAcceptable(signature).getPgpSignature();
            final PGPPublicKeyRing keyRing = getPublicKey(new PgpKeyId(
                    pgpSignature));
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredInputStream

        {
            if (!isPossiblyBase64(ch))
            {
                in.reset();
       
                return new ArmoredInputStream(in);
            }
           
            byte[]  buf = new byte[READ_AHEAD];
            int     count = 1;
            int     index = 1;
           
            buf[0] = (byte)ch;
            while (count != READ_AHEAD && (ch = in.read()) >= 0)
            {
                if (!isPossiblyBase64(ch))
                {
                    in.reset();
                   
                    return new ArmoredInputStream(in);
                }
               
                if (ch != '\n' && ch != '\r')
                {
                    buf[index++] = (byte)ch;
                }
               
                count++;
            }
           
            in.reset();
       
            //
            // nothing but new lines, little else, assume regular armoring
            //
            if (count < 4)
            {
                return new ArmoredInputStream(in);
            }
           
            //
            // test our non-blank data
            //
            byte[]    firstBlock = new byte[8];
           
            System.arraycopy(buf, 0, firstBlock, 0, firstBlock.length);

            byte[]    decoded = Base64.decode(firstBlock);
           
            //
            // it's a base64 PGP block.
            //
            if ((decoded[0] & 0x80) != 0)
            {
                return new ArmoredInputStream(in, false);
            }
           
            return new ArmoredInputStream(in);
        }
    }
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredInputStream

        InputStream        in,
        InputStream        keyIn,
        String             resultName)
        throws Exception
    {
        ArmoredInputStream    aIn = new ArmoredInputStream(in);
        OutputStream          out = new BufferedOutputStream(new FileOutputStream(resultName));



        //
        // write out signed section using the local line separator.
        // note: although we leave it in trailing white space as it is not verifiable.
        // Some people prefer to remove it.
        //
        ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
        int                   lookAhead = readInputLine(lineOut, aIn);
        byte[]                lineSep = getLineSeparator();

        if (lookAhead != -1 && aIn.isClearText())
        {
            byte[] line = lineOut.toByteArray();
            out.write(line, 0, getLengthWithoutSeperator(line));
            out.write(lineSep);

            while (lookAhead != -1 && aIn.isClearText())
            {
                lookAhead = readInputLine(lineOut, lookAhead, aIn);
               
                line = lineOut.toByteArray();
                out.write(line, 0, getLengthWithoutSeperator(line));
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.