Package org.bouncycastle.openpgp

Examples of org.bouncycastle.openpgp.PGPPublicKeyRingCollection


        "AQE=");

    public void test1()
        throws Exception
    {
        PGPPublicKeyRingCollection    pubRings = new PGPPublicKeyRingCollection(pub1);

        int                                        count = 0;

        Iterator    rIt = pubRings.getKeyRings();
       
        while (rIt.hasNext())
        {
            PGPPublicKeyRing                    pgpPub = (PGPPublicKeyRing)rIt.next();

            count++;
           
            int    keyCount = 0;
           
            byte[]    bytes = pgpPub.getEncoded();
           
            pgpPub = new PGPPublicKeyRing(bytes);
           
            Iterator    it = pgpPub.getPublicKeys();
            while (it.hasNext())
            {
                keyCount++;

                PGPPublicKey    pubKey = (PGPPublicKey)it.next();
               
                Iterator   sIt = pubKey.getSignatures();
                while (sIt.hasNext())
                {
                    ((PGPSignature)sIt.next()).getSignatureType();
                }
            }
           
            if (keyCount != 2)
            {
                fail("wrong number of public keys");
            }
        }
       
        if (count != 1)
        {
            fail("wrong number of public keyrings");
        }
       
        //
        // exact match
        //
        rIt = pubRings.getKeyRings("test (Test key) <test@ubicall.com>");
        count = 0;
        while (rIt.hasNext())
        {
            count++;
            rIt.next();
        }
       
        if (count != 1)
        {
            fail("wrong number of public keyrings on exact match");
        }
       
        //
        // partial match 1 expected
        //
        rIt = pubRings.getKeyRings("test", true);
        count = 0;
        while (rIt.hasNext())
        {
            count++;
            rIt.next();
        }
       
        if (count != 1)
        {
            fail("wrong number of public keyrings on partial match 1");
        }
       
        //
        // partial match 0 expected
        //
        rIt = pubRings.getKeyRings("XXX", true);
        count = 0;
        while (rIt.hasNext())
        {
            count++;
            rIt.next();
        }
       
        if (count != 0)
        {
            fail("wrong number of public keyrings on partial match 0");
        }

        //
        // case-insensitive partial match
        //
        rIt = pubRings.getKeyRings("TEST@ubicall.com", true, true);
        count = 0;
        while (rIt.hasNext())
        {
            count++;
            rIt.next();
View Full Code Here


    }
   
    public void test2()
        throws Exception
    {
        PGPPublicKeyRingCollection    pubRings = new PGPPublicKeyRingCollection(pub2);

        int                            count = 0;

        byte[]    encRing = pubRings.getEncoded();

        pubRings = new PGPPublicKeyRingCollection(encRing);
       
        Iterator    rIt = pubRings.getKeyRings();
       
        while (rIt.hasNext())
        {
            PGPPublicKeyRing        pgpPub = (PGPPublicKeyRing)rIt.next();
           
View Full Code Here

    }
   
    public void test3()
        throws Exception
    {
        PGPPublicKeyRingCollection    pubRings = new PGPPublicKeyRingCollection(pub3);

        int                                        count = 0;

        byte[]    encRing = pubRings.getEncoded();

        pubRings = new PGPPublicKeyRingCollection(encRing);
       
        Iterator    rIt = pubRings.getKeyRings();
       
        while (rIt.hasNext())
        {
            PGPPublicKeyRing                    pgpPub = (PGPPublicKeyRing)rIt.next();
           
View Full Code Here

    }

    public void test5()
        throws Exception
    {
        PGPPublicKeyRingCollection    pubRings = new PGPPublicKeyRingCollection(pub5);

        int                           count = 0;

        byte[]    encRing = pubRings.getEncoded();

        pubRings = new PGPPublicKeyRingCollection(encRing);
       
        Iterator    rIt = pubRings.getKeyRings();
       
        while (rIt.hasNext())
        {
            PGPPublicKeyRing                    pgpPub = (PGPPublicKeyRing)rIt.next();
           
View Full Code Here

    }

    public void test6()
        throws Exception
    {
        PGPPublicKeyRingCollection  pubRings = new PGPPublicKeyRingCollection(pub6);
        Iterator                    rIt = pubRings.getKeyRings();

        while (rIt.hasNext())
        {
            PGPPublicKeyRing    pgpPub = (PGPPublicKeyRing)rIt.next();
            Iterator            it = pgpPub.getPublicKeys();
            while (it.hasNext())
            {
                PGPPublicKey    k = (PGPPublicKey)it.next();

                if (k.getKeyID() == 0x5ce086b5b5a18ff4L)
                {
                    int             count = 0;
                    Iterator        sIt = k.getSignaturesOfType(PGPSignature.SUBKEY_REVOCATION);
                    while (sIt.hasNext())
                    {
                        PGPSignature sig = (PGPSignature)sIt.next();
                        count++;
                    }
                   
                    if (count != 1)
                    {
                        fail("wrong number of revocations in test6.");
                    }
                }
            }
        }
       
        byte[]    encRing = pubRings.getEncoded();
    }
View Full Code Here

           
        PGPLiteralData              p2 = (PGPLiteralData)pgpFact.nextObject();

        InputStream                 dIn = p2.getInputStream();
        int                         ch;
        PGPPublicKeyRingCollection  pgpRing = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(keyIn));

        PGPPublicKey                key = pgpRing.getPublicKey(ops.getKeyID());
        FileOutputStream            out = new FileOutputStream(p2.getFileName());

        ops.initVerify(key, "BC");
           
        while ((ch = dIn.read()) >= 0)
View Full Code Here

    }

    public void test8()
        throws Exception
    {
        PGPPublicKeyRingCollection    pubRings = new PGPPublicKeyRingCollection(pub8);

        int                           count = 0;

        byte[]    encRing = pubRings.getEncoded();

        pubRings = new PGPPublicKeyRingCollection(encRing);
       
        Iterator    rIt = pubRings.getKeyRings();
       
        while (rIt.hasNext())
        {
            PGPPublicKeyRing          pgpPub = (PGPPublicKeyRing)rIt.next();
           
View Full Code Here

    private static PGPPublicKey readPublicKey(InputStream in)
            throws IOException, PGPException {
        in = PGPUtil.getDecoderStream(in);

        PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(in);

        //
        // we just loop through the collection till we find a key suitable for
        // encryption, in the real
        // world you would probably want to be a bit smarter about this.
        //

        //
        // iterate through the key rings.
        //
        Iterator rIt = pgpPub.getKeyRings();

        while (rIt.hasNext()) {
            PGPPublicKeyRing kRing = (PGPPublicKeyRing) rIt.next();
            Iterator kIt = kRing.getPublicKeys();
View Full Code Here

     *             if an error is thrown by the underlying crypto library. Use
     *             <code>getUnderlyingException()</code> to see the cause of the error
     */
    public static PGPPublicKey readKey(InputStream in, long keyId) throws IOException, PGPException {
        InputStream wrapped = PGPUtil.getDecoderStream(in);
        PGPPublicKeyRingCollection keyRings = new PGPPublicKeyRingCollection(wrapped);
        return keyRings.getPublicKey(keyId);
    }
View Full Code Here

     *             if an error is thrown by the underlying crypto library. Use
     *             <code>getUnderlyingException()</code> to see the cause of the error
     */
    public static PGPPublicKey[] readKeys(InputStream in, String userId) throws IOException, PGPException {
        InputStream wrapped = PGPUtil.getDecoderStream(in);
        PGPPublicKeyRingCollection keyRings = new PGPPublicKeyRingCollection(wrapped);
        List<PGPPublicKey> keys = new ArrayList<PGPPublicKey>();
        for (Iterator rIt = keyRings.getKeyRings(userId); rIt.hasNext();) {
            for (Iterator kIt = ((PGPPublicKeyRing) rIt.next()).getPublicKeys(); kIt.hasNext();) {
                PGPPublicKey key = (PGPPublicKey) kIt.next();
                if (key.isEncryptionKey()) {
                    keys.add(key);
                }
View Full Code Here

TOP

Related Classes of org.bouncycastle.openpgp.PGPPublicKeyRingCollection

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.