Package org.bouncycastle.bcpg

Examples of org.bouncycastle.bcpg.ArmoredOutputStream


    {
        //
        // test immediate close
        //
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        ArmoredOutputStream aOut = new ArmoredOutputStream(bOut);

        aOut.close();

        byte[] data = bOut.toByteArray();

        if (data.length != 0)
        {
            fail("No data should have been written");
        }

        //
        // multiple close
        //
        bOut = new ByteArrayOutputStream();
        aOut = new ArmoredOutputStream(bOut);

        aOut.write(sample);

        aOut.close();

        aOut.close();

        int mc = markerCount(bOut.toByteArray());

        if (mc < 1)
        {
            fail("No end marker found");
        }

        if (mc > 1)
        {
            fail("More than one end marker found");
        }

        //
        // writing and reading single objects
        //
        bOut = new ByteArrayOutputStream();
        aOut = new ArmoredOutputStream(bOut);

        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;
View Full Code Here


        boolean         armor)
        throws IOException, InvalidKeyException, NoSuchProviderException, SignatureException, PGPException
    {   
        if (armor)
        {
            secretOut = new ArmoredOutputStream(secretOut);
        }

        PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
        PGPKeyPair          keyPair = new PGPKeyPair(PGPPublicKey.RSA_GENERAL, publicKey, privateKey, new Date());
        PGPSecretKey        secretKey = new PGPSecretKey(PGPSignature.DEFAULT_CERTIFICATION, keyPair, identity, sha1Calc, null, null, new JcaPGPContentSignerBuilder(keyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.CAST5, sha1Calc).setProvider("BC").build(passPhrase));
       
        secretKey.encode(secretOut);
       
        secretOut.close();
       
        if (armor)
        {
            publicOut = new ArmoredOutputStream(publicOut);
        }

        PGPPublicKey    key = secretKey.getPublicKey();
       
        key.encode(publicOut);
View Full Code Here

            // create the signed keyRing
            PGPPublicKeyRing sRing = new PGPPublicKeyRing(new ByteArrayInputStream(signPublicKey(secRing.getSecretKey(), secretKeyPass, ring.getPublicKey(), notationName, notationValue, true)), new JcaKeyFingerprintCalculator());
            ring = sRing;

            // write the created keyRing to file
            ArmoredOutputStream out = new ArmoredOutputStream(new FileOutputStream("SignedKey.asc"));
            sRing.encode(out);
            out.flush();
            out.close();
        }
        else
        {
            System.err.println("usage: DirectKeySignature secretKeyFile secretKeyPass publicKeyFile(key to be signed) NotationName NotationValue");
            System.err.println("or: DirectKeySignature signedPublicKeyFile");
View Full Code Here

    {
        OutputStream out = new ByteArrayOutputStream();

        if (armor)
        {
            out = new ArmoredOutputStream(out);
        }

        PGPPrivateKey pgpPrivKey = secretKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(secretKeyPass.toCharArray()));

        PGPSignatureGenerator       sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(secretKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1).setProvider("BC"));
View Full Code Here

        boolean         withIntegrityCheck)
        throws IOException, NoSuchProviderException
    {   
        if (armor)
        {
            out = new ArmoredOutputStream(out);
        }
       
        try
        {   
            PGPEncryptedDataGenerator   cPk = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).setWithIntegrityPacket(withIntegrityCheck).setSecureRandom(new SecureRandom()).setProvider("BC"));
View Full Code Here

            spGen.setSignerUserID(false, (String)it.next());
            sGen.setHashedSubpackets(spGen.generate());
        }
       
        InputStream fIn = new BufferedInputStream(new FileInputStream(fileName));
        ArmoredOutputStream aOut = new ArmoredOutputStream(out);
       
        aOut.beginClearText(digest);

        //
        // note the last \n/\r/\r\n in the file is ignored
        //
        ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
        int lookAhead = readInputLine(lineOut, fIn);

        processLine(aOut, sGen, lineOut.toByteArray());

        if (lookAhead != -1)
        {
            do
            {
                lookAhead = readInputLine(lineOut, lookAhead, fIn);

                sGen.update((byte)'\r');
                sGen.update((byte)'\n');

                processLine(aOut, sGen, lineOut.toByteArray());
            }
            while (lookAhead != -1);
        }

        fIn.close();

        aOut.endClearText();
       
        BCPGOutputStream            bOut = new BCPGOutputStream(aOut);
       
        sGen.generate().encode(bOut);

        aOut.close();
    }
View Full Code Here

        boolean         armor)
        throws GeneralSecurityException, IOException, PGPException
    {   
        if (armor)
        {
            out = new ArmoredOutputStream(out);
        }

        PGPSecretKey             pgpSec = PGPExampleUtil.readSecretKey(keyIn);
        PGPPrivateKey            pgpPrivKey = pgpSec.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pass));
        PGPSignatureGenerator    sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(), PGPUtil.SHA1).setProvider("BC"));
View Full Code Here

        boolean         armor)
        throws IOException, NoSuchAlgorithmException, NoSuchProviderException, PGPException, SignatureException
    {
        if (armor)
        {
            out = new ArmoredOutputStream(out);
        }

        PGPSecretKey                pgpSec = PGPExampleUtil.readSecretKey(keyIn);
        PGPPrivateKey               pgpPrivKey = pgpSec.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pass));
        PGPSignatureGenerator       sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(), PGPUtil.SHA1).setProvider("BC"));
View Full Code Here

        ByteArrayOutputStream bOut = new ByteArrayOutputStream();

        OutputStream out = bOut;
        if (armor)
        {
            out = new ArmoredOutputStream(out);
        }

        PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(algorithm).setSecureRandom(new SecureRandom()).setProvider("BC"));
        encGen.addMethod(new JcePBEKeyEncryptionMethodGenerator(passPhrase).setProvider("BC"));
View Full Code Here

        boolean         withIntegrityCheck)
        throws IOException, NoSuchProviderException
    {
        if (armor)
        {
            out = new ArmoredOutputStream(out);
        }

        try
        {
            byte[] bytes = PGPExampleUtil.compressFile(fileName, CompressionAlgorithmTags.ZIP);
View Full Code Here

TOP

Related Classes of org.bouncycastle.bcpg.ArmoredOutputStream

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.