Examples of BCPGOutputStream


Examples of org.bouncycastle.bcpg.BCPGOutputStream

            PGPSignatureGenerator sGen = new PGPSignatureGenerator(pgpSec.getPublicKey()
                    .getAlgorithm(), PGPUtil.SHA1, BouncyCastleProvider.PROVIDER_NAME);
            sGen.initSign(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);

            in = new FileInputStream(src);
            out = new BCPGOutputStream(new ArmoredOutputStream(new FileOutputStream(dest)));

            int ch = 0;
            while ((ch = in.read()) >= 0) {
                sGen.update((byte) ch);
            }
View Full Code Here

Examples of org.bouncycastle.bcpg.BCPGOutputStream

        PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(),
                PGPUtil.SHA1).setProvider(getProvider()));

        sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);

        BCPGOutputStream bOut = new BCPGOutputStream(out);

        InputStream fIn = new ByteArrayInputStream("Test Signature".getBytes("UTF-8"));

        int ch;
        while ((ch = fIn.read()) >= 0) {
View Full Code Here

Examples of org.bouncycastle.bcpg.BCPGOutputStream

        PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(),
                PGPUtil.SHA1).setProvider(getProvider()));

        sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);

        BCPGOutputStream bOut = new BCPGOutputStream(out);

        InputStream fIn = new ByteArrayInputStream("Test Signature".getBytes("UTF-8"));

        int ch;
        while ((ch = fIn.read()) >= 0) {
View Full Code Here

Examples of org.bouncycastle.bcpg.BCPGOutputStream

            throw new IllegalStateException("provider resolves to null");
        }

        Key key = null;

        pOut = new BCPGOutputStream(out);

        if (methods.size() == 1)
        {   
            if (methods.get(0) instanceof PBEMethod)
            {
                PBEMethod m = (PBEMethod)methods.get(0);
               
                key = m.getKey();
            }
            else
            {
                key = PGPUtil.makeRandomKey(defAlgorithm, rand);
                byte[] sessionInfo = createSessionInfo(defAlgorithm, key);

                PubMethod m = (PubMethod)methods.get(0);

                try
                {
                    m.addSessionInfo(sessionInfo);
                }
                catch (Exception e)
                {
                    throw new PGPException("exception encrypting session key", e);
                }
            }
           
            pOut.writePacket((ContainedPacket)methods.get(0));
        }
        else // multiple methods
        {
            key = PGPUtil.makeRandomKey(defAlgorithm, rand);
            byte[] sessionInfo = createSessionInfo(defAlgorithm, key);

            for (int i = 0; i != methods.size(); i++)
            {
                EncMethod m = (EncMethod)methods.get(i);

                try
                {
                    m.addSessionInfo(sessionInfo);
                }
                catch (Exception e)
                {
                    throw new PGPException("exception encrypting session key", e);
                }

                pOut.writePacket(m);
            }
        }

        String cName = PGPUtil.getSymmetricCipherName(defAlgorithm);

        if (cName == null)
        {
            throw new PGPException("null cipher specified");
        }

        try
        {
            if (withIntegrityPacket)
            {
                c = Cipher.getInstance(cName + "/CFB/NoPadding", defProvider);
            }
            else
            {
                c = Cipher.getInstance(cName + "/OpenPGPCFB/NoPadding", defProvider);
            }

            byte[] iv = new byte[c.getBlockSize()];
            c.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv), rand);
           
            if (buffer == null)
            {
                //
                // we have to add block size + 2 for the generated IV and + 1 + 22 if integrity protected
                //
                if (withIntegrityPacket)
                {
                    pOut = new BCPGOutputStream(out, PacketTags.SYM_ENC_INTEGRITY_PRO, length + c.getBlockSize() + 2 + 1 + 22);
                    pOut.write(1);        // version number
                }
                else
                {
                    pOut = new BCPGOutputStream(out, PacketTags.SYMMETRIC_KEY_ENC, length + c.getBlockSize() + 2, oldFormat);
                }
            }
            else
            {
                if (withIntegrityPacket)
                {
                    pOut = new BCPGOutputStream(out, PacketTags.SYM_ENC_INTEGRITY_PRO, buffer);
                    pOut.write(1);        // version number
                }
                else
                {
                    pOut = new BCPGOutputStream(out, PacketTags.SYMMETRIC_KEY_ENC, buffer);
                }
            }


            OutputStream genOut = cOut = new CipherOutputStream(pOut, c);
View Full Code Here

Examples of org.bouncycastle.bcpg.BCPGOutputStream

            if (digestOut != null)
            {
                //
                // hand code a mod detection packet
                //
                BCPGOutputStream bOut = new BCPGOutputStream(digestOut, PacketTags.MOD_DETECTION_CODE, 20);

                bOut.flush();
                digestOut.flush();

                byte[] dig = digestOut.getMessageDigest().digest();

                cOut.write(dig);
View Full Code Here

Examples of org.bouncycastle.bcpg.BCPGOutputStream

   
    public void encode(
        OutputStream    outStream)
        throws IOException
    {
        BCPGOutputStream    out;
       
        if (outStream instanceof BCPGOutputStream)
        {
            out = (BCPGOutputStream)outStream;
        }
        else
        {
            out = new BCPGOutputStream(outStream);
        }

        out.writePacket(sigPack);
    }
View Full Code Here

Examples of org.bouncycastle.bcpg.BCPGOutputStream

   
    public void encode(
        OutputStream    outStream)
        throws IOException
    {
        BCPGOutputStream    out;
       
        if (outStream instanceof BCPGOutputStream)
        {
            out = (BCPGOutputStream)outStream;
        }
        else
        {
            out = new BCPGOutputStream(outStream);
        }
       
        out.writePacket(publicPk);
        if (trustPk != null)
        {
            out.writePacket(trustPk);
        }
       
        if (subSigs == null)    // not a sub-key
        {
            for (int i = 0; i != keySigs.size(); i++)
            {
                ((PGPSignature)keySigs.get(i)).encode(out);
            }
           
            for (int i = 0; i != ids.size(); i++)
            {
                if (ids.get(i) instanceof String)
                {
                    String    id = (String)ids.get(i);
                   
                    out.writePacket(new UserIDPacket(id));
                }
                else
                {
                    PGPUserAttributeSubpacketVector    v = (PGPUserAttributeSubpacketVector)ids.get(i);

                    out.writePacket(new UserAttributePacket(v.toSubpacketArray()));
                }
               
                if (idTrusts.get(i) != null)
                {
                    out.writePacket((ContainedPacket)idTrusts.get(i));
                }
               
                List    sigs = (List)idSigs.get(i);
                for (int j = 0; j != sigs.size(); j++)
                {
View Full Code Here

Examples of org.bouncycastle.bcpg.BCPGOutputStream

        if (pkOut != null)
        {
            throw new IllegalStateException("generator already in open state");
        }

        pkOut = new BCPGOutputStream(out, PacketTags.LITERAL_DATA, length + 2 + name.length() + 4, oldFormat);
       
        writeHeader(pkOut, format, name, modificationTime.getTime());

        return new WrappedGeneratorStream(pkOut, this);
    }
View Full Code Here

Examples of org.bouncycastle.bcpg.BCPGOutputStream

        if (pkOut != null)
        {
            throw new IllegalStateException("generator already in open state");
        }

        pkOut = new BCPGOutputStream(out, PacketTags.LITERAL_DATA, buffer);
       
        writeHeader(pkOut, format, name, modificationTime.getTime());

        return new WrappedGeneratorStream(pkOut, this);
    }
View Full Code Here

Examples of org.bouncycastle.bcpg.BCPGOutputStream

        if (pkOut != null)
        {
            throw new IllegalStateException("generator already in open state");
        }

        pkOut = new BCPGOutputStream(out, PacketTags.LITERAL_DATA, file.length() + 2 + file.getName().length() + 4, oldFormat);
       
        writeHeader(pkOut, format, file.getName(), file.lastModified());

        return new WrappedGeneratorStream(pkOut, this);
    }
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.