Package org.bouncycastle.openpgp.jcajce

Examples of org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory


    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


            PGPException {
        final ByteArrayInputStream keyIn = new ByteArrayInputStream(
                publicKeyRing);
        final InputStream decoderInputStream = PGPUtil.getDecoderStream(inputStream);

        PGPObjectFactory pgpFact = new JcaPGPObjectFactory(decoderInputStream);
        final PGPCompressedData c1 = (PGPCompressedData) pgpFact.nextObject();
        pgpAssertNotNull(c1);
        pgpFact = new JcaPGPObjectFactory(c1.getDataStream());
        final PGPOnePassSignatureList p1 = (PGPOnePassSignatureList) pgpFact
                .nextObject();

        pgpAssertNotNull(p1);
        final PGPOnePassSignature ops = p1.get(0);
        final PGPLiteralData p2 = (PGPLiteralData) pgpFact.nextObject();

        pgpAssertNotNull(p2);
        final InputStream dIn = p2.getInputStream();
        pgpAssertNotNull(dIn);
        int ch;
        final PGPPublicKeyRingCollection pgpRing = new PGPPublicKeyRingCollection(
                PGPUtil.getDecoderStream(keyIn));
        pgpAssertNotNull(ops);
        decodeKeyId = ops.getKeyID();
        if (decodeKeyId == null) {
            // there is no key in the key ring that can decode the license
            verified = false;
            licenseProperties = null;
        } else {
            final PGPPublicKey decodeKey = pgpRing.getPublicKey(decodeKeyId);
            final ByteArrayOutputStream out = new ByteArrayOutputStream();
            try {
                final PGPContentVerifierBuilderProvider cvBuilder = new JcaPGPContentVerifierBuilderProvider();
                ops.init(cvBuilder, decodeKey);
                while ((ch = dIn.read()) >= 0) {
                    ops.update((byte) ch);
                    out.write(ch);
                }
                final PGPSignatureList p3 = (PGPSignatureList) pgpFact
                        .nextObject();

                if (ops.verify(p3.get(0))) {
                    setLicense(new String(out.toByteArray()));
                    verified = true;
View Full Code Here

TOP

Related Classes of org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory

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.