Examples of PGPObjectFactory


Examples of org.bouncycastle.openpgp.PGPObjectFactory

            return null;
        }
        InputStream in = PGPUtil.getDecoderStream(encryptedStream);
        InputStream encData = getDecryptedData(exchange, in);
        InputStream uncompressedData = getUncompressedData(encData);
        PGPObjectFactory pgpFactory = new PGPObjectFactory(uncompressedData);
        Object object = pgpFactory.nextObject();

        PGPOnePassSignature signature;
        if (object instanceof PGPOnePassSignatureList) {
            signature = getSignature(exchange, (PGPOnePassSignatureList) object);
            object = pgpFactory.nextObject();
        } else {
            // no signature contained in PGP message
            signature = null;
            if (SIGNATURE_VERIFICATION_OPTION_REQUIRED.equals(getSignatureVerificationOption())) {
                throw new PGPException(
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPObjectFactory

            return bos.toByteArray();
        }
    }

    private InputStream getUncompressedData(InputStream encData) throws IOException, PGPException {
        PGPObjectFactory pgpFactory = new PGPObjectFactory(encData);
        Object compObj = pgpFactory.nextObject();
        if (!(compObj instanceof PGPCompressedData)) {
            throw getFormatException();
        }
        PGPCompressedData comData = (PGPCompressedData) compObj;
        InputStream uncompressedData = comData.getDataStream();
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPObjectFactory

        InputStream uncompressedData = comData.getDataStream();
        return uncompressedData;
    }

    private InputStream getDecryptedData(Exchange exchange, InputStream encryptedStream) throws Exception, PGPException {
        PGPObjectFactory pgpFactory = new PGPObjectFactory(encryptedStream);
        Object firstObject = pgpFactory.nextObject();
        // the first object might be a PGP marker packet
        PGPEncryptedDataList enc = getEcryptedDataList(pgpFactory, firstObject);

        if (enc == null) {
            throw getFormatException();
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPObjectFactory

        try {
            in = PGPUtil.getDecoderStream(encryptedStream);
            encData = getDecryptedData(exchange, in);
            uncompressedData = getUncompressedData(encData);
            PGPObjectFactory pgpFactory = new PGPObjectFactory(uncompressedData);
            Object object = pgpFactory.nextObject();

            PGPOnePassSignature signature;
            if (object instanceof PGPOnePassSignatureList) {
                signature = getSignature(exchange, (PGPOnePassSignatureList) object);
                object = pgpFactory.nextObject();
            } else {
                // no signature contained in PGP message
                signature = null;
                if (SIGNATURE_VERIFICATION_OPTION_REQUIRED.equals(getSignatureVerificationOption())) {
                    throw new PGPException(
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPObjectFactory

            return bos.toByteArray();
        }
    }

    private InputStream getUncompressedData(InputStream encData) throws IOException, PGPException {
        PGPObjectFactory pgpFactory = new PGPObjectFactory(encData);
        Object compObj = pgpFactory.nextObject();
        if (!(compObj instanceof PGPCompressedData)) {
            throw getFormatException();
        }
        PGPCompressedData comData = (PGPCompressedData) compObj;
        InputStream uncompressedData = comData.getDataStream();
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPObjectFactory

        InputStream uncompressedData = comData.getDataStream();
        return uncompressedData;
    }

    private InputStream getDecryptedData(Exchange exchange, InputStream encryptedStream) throws Exception, PGPException {
        PGPObjectFactory pgpFactory = new PGPObjectFactory(encryptedStream);
        Object firstObject = pgpFactory.nextObject();
        // the first object might be a PGP marker packet
        PGPEncryptedDataList enc = getEcryptedDataList(pgpFactory, firstObject);

        if (enc == null) {
            throw getFormatException();
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPObjectFactory

    @Deprecated
    private static PGPPrivateKey findPrivateKey(InputStream keyringInput, InputStream encryptedInput, String passphrase,
            PGPPassphraseAccessor passphraseAccessor, String provider) throws IOException, PGPException, NoSuchProviderException {
        PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(keyringInput));
        PGPObjectFactory factory = new PGPObjectFactory(PGPUtil.getDecoderStream(encryptedInput));
        PGPEncryptedDataList enc;
        Object o = factory.nextObject();
        if (o == null) {
            throw new PGPException("Provided input is not encrypted.");
        }
        if (o instanceof PGPEncryptedDataList) {
            enc = (PGPEncryptedDataList) o;
        } else {
            enc = (PGPEncryptedDataList) factory.nextObject();
        }
        encryptedInput.reset(); // nextObject() method reads from the InputStream, so rewind it!
        Iterator<?> encryptedDataObjects = enc.getEncryptedDataObjects();
        PGPPrivateKey privateKey = null;
        PGPPublicKeyEncryptedData encryptedData = null;
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPObjectFactory

        }

        InputStream in = new ByteArrayInputStream(IOUtils.toByteArray(encryptedStream));
        in = PGPUtil.getDecoderStream(in);

        PGPObjectFactory pgpF = new PGPObjectFactory(in);
        PGPEncryptedDataList enc;
        Object o = pgpF.nextObject();

        // the first object might be a PGP marker packet.
        if (o instanceof PGPEncryptedDataList) {
            enc = (PGPEncryptedDataList) o;
        } else {
            enc = (PGPEncryptedDataList) pgpF.nextObject();
        }

        PGPPublicKeyEncryptedData pbe = (PGPPublicKeyEncryptedData) enc.get(0);
        InputStream clear = pbe.getDataStream(key, "BC");

        PGPObjectFactory pgpFact = new PGPObjectFactory(clear);
        PGPCompressedData cData = (PGPCompressedData) pgpFact.nextObject();
        pgpFact = new PGPObjectFactory(cData.getDataStream());
        PGPLiteralData ld = (PGPLiteralData) pgpFact.nextObject();
        return Streams.readAll(ld.getInputStream());
    }
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPObjectFactory

     */
    @Override
    public void initialize(OutputStream out) throws Exception
    {
        InputStream decodedInputStream = PGPUtil.getDecoderStream(this.toBeDecrypted);
        PGPObjectFactory pgpF = new PGPObjectFactory(decodedInputStream);
        Object pgpObject = pgpF.nextObject();

        if (pgpObject == null)
        {
            throw new IllegalArgumentException("Invalid PGP message");
        }

        // the first object might be a PGP marker packet.
        PGPEncryptedDataList enc;
        if (pgpObject instanceof PGPEncryptedDataList)
        {
            enc = (PGPEncryptedDataList) pgpObject;

        }
        else
        {
            enc = (PGPEncryptedDataList) pgpF.nextObject();
        }

        // This loop looks like it is ready for multiple encrypted
        // objects, but really only one is expected.
        Iterator<?> it = enc.getEncryptedDataObjects();
        PGPPublicKeyEncryptedData pbe = null;
        PGPPrivateKey privateKey = null;
        while (privateKey == null && it.hasNext())
        {
            pbe = (PGPPublicKeyEncryptedData) it.next();
            privateKey = getPrivateKey(pbe.getKeyID(), this.password);
            if (privateKey == null)
            {
                throw new IllegalArgumentException("Failed to find private key with ID " + pbe.getKeyID());
            }
        }

        clearStream = pbe.getDataStream(privateKey, provider);
        PGPObjectFactory pgpObjectFactory = new PGPObjectFactory(clearStream);

        pgpObject = pgpObjectFactory.nextObject();

        while (!(pgpObject instanceof PGPLiteralData))
        {
            if (pgpObject instanceof PGPOnePassSignatureList)
            {
                PGPOnePassSignature signature = null;
                PGPOnePassSignatureList list = (PGPOnePassSignatureList) pgpObject;
                signature = list.get(0);
                signature.initVerify(this.publicKey, provider);
                // TODO verify signature
                // signature.verify(null);
                pgpObject = pgpObjectFactory.nextObject();
            }
            else if (pgpObject instanceof PGPCompressedData)
            {
                PGPCompressedData cData = (PGPCompressedData) pgpObject;
                compressedStream = new BufferedInputStream(cData.getDataStream());
                pgpObjectFactory = new PGPObjectFactory(compressedStream);
                pgpObject = pgpObjectFactory.nextObject();
            }
            else
            {
                throw new PGPException("input is not PGPLiteralData - type unknown.");
            }
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPObjectFactory

    try {

      in = PGPUtil.getDecoderStream(stream);

      final PGPObjectFactory pgpF = new JcaPGPObjectFactory(in);
      PGPEncryptedDataList enc;
      final Object o = pgpF.nextObject();

      // the first object might be a PGP marker packet.
      if (o instanceof PGPEncryptedDataList) {
        enc = (PGPEncryptedDataList) o;
      } else {
        enc = (PGPEncryptedDataList) pgpF.nextObject();
      }

      final PGPPBEEncryptedData pbe = (PGPPBEEncryptedData) enc.get(0);

      final InputStream clear = pbe.getDataStream(new JcePBEDataDecryptorFactoryBuilder(new JcaPGPDigestCalculatorProviderBuilder().setProvider("BC").build()).setProvider("BC").build(
          passphrase.toCharArray()));

      PGPObjectFactory pgpFact = new JcaPGPObjectFactory(clear);

      final PGPCompressedData cData = (PGPCompressedData) pgpFact.nextObject();

      pgpFact = new JcaPGPObjectFactory(cData.getDataStream());
     
      final PGPLiteralData ld = (PGPLiteralData) pgpFact.nextObject();

      return Streams.readAll(ld.getInputStream());
    } catch (Exception e) {
      throw new CloudsyncException("can't encrypt data", e);
    } finally {
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.