Package org.bouncycastle.openpgp

Examples of org.bouncycastle.openpgp.PGPPublicKey


            pgpPub = new PGPPublicKeyRing(bytes);
           
            Iterator    it = pgpPub.getPublicKeys();
            while (it.hasNext())
            {
                PGPPublicKey    pk = (PGPPublicKey)it.next();
               
                byte[] pkBytes = pk.getEncoded();
               
                PGPPublicKeyRing  pkR = new PGPPublicKeyRing(pkBytes);
               
                keyCount++;
            }
           
            if (keyCount != 2)
            {
                fail("wrong number of public keys");
            }
        }
       
        if (count != 2)
        {
            fail("wrong number of public keyrings");
        }
       
        PGPSecretKeyRingCollection    secretRings = new PGPSecretKeyRingCollection(sec2);

        rIt = secretRings.getKeyRings();
        count = 0;
       
        encRing = secretRings.getEncoded();
       
        secretRings = new PGPSecretKeyRingCollection(encRing);
       
        while (rIt.hasNext())
        {
            PGPSecretKeyRing                    pgpSec = (PGPSecretKeyRing)rIt.next();
   
            count++;
           
            int    keyCount = 0;
           
            byte[]    bytes = pgpSec.getEncoded();
           
            pgpSec = new PGPSecretKeyRing(bytes);
           
            Iterator    it = pgpSec.getSecretKeys();
            while (it.hasNext())
            {
                keyCount++;

                PGPSecretKey    k = (PGPSecretKey)it.next();
                PGPPublicKey    pk = k.getPublicKey();

                if (pk.getKeyID() == -1413891222336124627L)
                {
                    int         sCount = 0;
                    Iterator    sIt = pk.getSignaturesOfType(PGPSignature.SUBKEY_BINDING);
                    while (sIt.hasNext())
                    {
                        int type = ((PGPSignature)sIt.next()).getSignatureType();
                        if (type != PGPSignature.SUBKEY_BINDING)
                        {
                            fail("failed to return correct signature type");
                        }
                        sCount++;
                    }
                   
                    if (sCount != 1)
                    {
                        fail("failed to find binding signature");
                    }
                }
               
                pk.getSignatures();
               
                if (k.getKeyID() == -4049084404703773049L
                     || k.getKeyID() == -1413891222336124627L)
                {
                    k.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(sec2pass1));
View Full Code Here


            Iterator    it = pgpPub.getPublicKeys();
            while (it.hasNext())
            {
                keyCount++;

                PGPPublicKey pubK = (PGPPublicKey)it.next();
               
                pubK.getSignatures();
            }
           
            if (keyCount != 2)
            {
                fail("wrong number of public keys");
View Full Code Here

            it = pgpSec.getPublicKeys();
            while (it.hasNext())
            {
                keyCount++;

                PGPPublicKey    k = (PGPPublicKey)it.next(); // make sure it's what we think it is!
            }

            if (keyCount != 2)
            {
                fail("test4 - wrong number of public keys");
View Full Code Here

        {
            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++;
                    }
View Full Code Here

    public void test7()
        throws Exception
    {
        PGPPublicKeyRing    pgpPub = new PGPPublicKeyRing(pub7);
        Iterator            it = pgpPub.getPublicKeys();
        PGPPublicKey        masterKey = null;

        while (it.hasNext())
        {
            PGPPublicKey    k = (PGPPublicKey)it.next();

            if (k.isMasterKey())
            {
                masterKey = k;
                continue;
            }
           
            int             count = 0;
            PGPSignature    sig = null;
            Iterator        sIt = k.getSignaturesOfType(PGPSignature.SUBKEY_REVOCATION);

            while (sIt.hasNext())
            {
                sig = (PGPSignature)sIt.next();
                count++;
View Full Code Here

        PGPSecretKeyRing    secretRing = new PGPSecretKeyRing(sec10);
        Iterator            secretKeys = secretRing.getSecretKeys();
       
        while (secretKeys.hasNext())
        {
            PGPPublicKey pubKey = ((PGPSecretKey)secretKeys.next()).getPublicKey();
           
            if (pubKey.getValidDays() != 28)
            {
                fail("days wrong on secret key ring");
            }
           
            if (pubKey.getValidSeconds() != 28 * 24 * 60 * 60)
            {
                fail("seconds wrong on secret key ring");
            }
        }
       
        PGPPublicKeyRing    publicRing = new PGPPublicKeyRing(pub10);
        Iterator            publicKeys = publicRing.getPublicKeys();
       
        while (publicKeys.hasNext())
        {
            PGPPublicKey pubKey = (PGPPublicKey)publicKeys.next();

            if (pubKey.getValidDays() != 28)
            {
                fail("days wrong on public key ring");
            }
           
            if (pubKey.getValidSeconds() != 28 * 24 * 60 * 60)
            {
                fail("seconds wrong on public key ring");
            }
        }
    }
View Full Code Here

       
        keyRing.getSecretKey().extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(passPhrase));
       
        PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
       
        PGPPublicKey            vKey = null;
        PGPPublicKey            sKey = null;
       
        Iterator                    it = pubRing.getPublicKeys();
        while (it.hasNext())
        {
            PGPPublicKey    pk = (PGPPublicKey)it.next();
            if (pk.isMasterKey())
            {
                vKey = pk;
            }
            else
            {
View Full Code Here

            fail("secret key public key mismatch");
        }

        PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
       
        PGPPublicKey            vKey = null;
        PGPPublicKey            sKey = null;
       
        Iterator                    it = pubRing.getPublicKeys();
        while (it.hasNext())
        {
            PGPPublicKey    pk = (PGPPublicKey)it.next();
            if (pk.isMasterKey())
            {
                vKey = pk;
            }
            else
            {
View Full Code Here

        PGPPublicKeyRing pubRing = new PGPPublicKeyRing(subKeyBindingKey);
        Iterator         it = pubRing.getPublicKeys();
       
        while (it.hasNext())
        {
            PGPPublicKey key = (PGPPublicKey)it.next();
           
            if (key.getValidSeconds() != 0)
            {
                fail("expiration time non-zero");
            }
        }
    }
View Full Code Here

    private void testUmlaut()
        throws Exception
    {
        PGPPublicKeyRing pubRing = new PGPPublicKeyRing(umlautKeySig);

        PGPPublicKey pub = pubRing.getPublicKey();
        String       userID = (String)pub.getUserIDs().next();

        for (Iterator it = pub.getSignatures(); it.hasNext();)
        {
            PGPSignature sig = (PGPSignature)it.next();

            if (sig.getSignatureType() == PGPSignature.POSITIVE_CERTIFICATION)
            {
                sig.initVerify(pub, "BC");

                if (!sig.verifyCertification(userID, pub))
                {
                    fail("failed UTF8 userID test");
                }
            }
        }

        //
        // this is quicker because we are using pregenerated parameters.
        //
        KeyPairGenerator  rsaKpg = KeyPairGenerator.getInstance("RSA", "BC");
        KeyPair           rsaKp = rsaKpg.generateKeyPair();
        PGPKeyPair        rsaKeyPair1 = new PGPKeyPair(PGPPublicKey.RSA_GENERAL, rsaKp, new Date());
                          rsaKp = rsaKpg.generateKeyPair();
        PGPKeyPair        rsaKeyPair2 = new PGPKeyPair(PGPPublicKey.RSA_GENERAL, rsaKp, new Date());
        char[]            passPhrase = "passwd".toCharArray();

        PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsaKeyPair1,
                userID, PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");

        PGPPublicKeyRing       pubRing1 = keyRingGen.generatePublicKeyRing();

        pub = pubRing1.getPublicKey();

        for (Iterator it = pub.getSignatures(); it.hasNext();)
        {
            PGPSignature sig = (PGPSignature)it.next();

            if (sig.getSignatureType() == PGPSignature.POSITIVE_CERTIFICATION)
            {
View Full Code Here

TOP

Related Classes of org.bouncycastle.openpgp.PGPPublicKey

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.