Examples of PGPOnePassSignatureList


Examples of org.bouncycastle.openpgp.PGPOnePassSignatureList

        PGPCompressedData       c1 = (PGPCompressedData)pgpFact.nextObject();

        pgpFact = new PGPObjectFactory(c1.getDataStream());
       
        PGPOnePassSignatureList p1 = (PGPOnePassSignatureList)pgpFact.nextObject();
       
        PGPOnePassSignature     ops = p1.get(0);
       
        PGPLiteralData          p2 = (PGPLiteralData)pgpFact.nextObject();

        InputStream             dIn = p2.getInputStream();
        int                     ch;

        ops.initVerify(pubKey, "BC");
       
        while ((ch = dIn.read()) >= 0)
        {
            ops.update((byte)ch);
        }

        PGPSignatureList        p3 = (PGPSignatureList)pgpFact.nextObject();

        if (!ops.verify(p3.get(0)))
        {
            fail("Failed signature check");
        }
       
        //
        // signature generation
        //
        generateTest(sKey, pubKey, pgpPrivKey);
       
        //
        // signature generation - canonical text
        //
        String                      data = "hello world!";
        ByteArrayOutputStream       bOut = new ByteArrayOutputStream();
        ByteArrayInputStream        testIn = new ByteArrayInputStream(data.getBytes());
        PGPSignatureGenerator       sGen = new PGPSignatureGenerator(PGPPublicKey.DSA, PGPUtil.SHA1, "BC");

        sGen.initSign(PGPSignature.CANONICAL_TEXT_DOCUMENT, pgpPrivKey);

        PGPCompressedDataGenerator  cGen = new PGPCompressedDataGenerator(
            PGPCompressedData.ZIP);

        BCPGOutputStream bcOut = new BCPGOutputStream(
            cGen.open(new UncloseableOutputStream(bOut)));

        sGen.generateOnePassVersion(false).encode(bcOut);

        PGPLiteralDataGenerator     lGen = new PGPLiteralDataGenerator();
        Date testDate = new Date((System.currentTimeMillis() / 1000) * 1000);
        OutputStream lOut = lGen.open(
            new UncloseableOutputStream(bcOut),
            PGPLiteralData.TEXT,
            "_CONSOLE",
            data.getBytes().length,
            testDate);

        while ((ch = testIn.read()) >= 0)
        {
            lOut.write(ch);
            sGen.update((byte)ch);
        }

        lGen.close();

        sGen.generate().encode(bcOut);

        cGen.close();

        //
        // verify generated signature - canconical text
        //
        pgpFact = new PGPObjectFactory(bOut.toByteArray());

        c1 = (PGPCompressedData)pgpFact.nextObject();

        pgpFact = new PGPObjectFactory(c1.getDataStream());
   
        p1 = (PGPOnePassSignatureList)pgpFact.nextObject();
   
        ops = p1.get(0);
   
        p2 = (PGPLiteralData)pgpFact.nextObject();
        if (!p2.getModificationTime().equals(testDate))
        {
            fail("Modification time not preserved");
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPOnePassSignatureList

        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);
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.