Examples of PGPSecretKeyRingCollection


Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

    }
   
    public void test9()
        throws Exception
    {
        PGPSecretKeyRingCollection    secretRings = new PGPSecretKeyRingCollection(sec9);

        Iterator    rIt = secretRings.getKeyRings();
        int         count = 0;
       
        byte[] encRing = secretRings.getEncoded();
       
        secretRings = new PGPSecretKeyRingCollection(encRing);
       
        while (rIt.hasNext())
        {
            PGPSecretKeyRing         pgpSec = (PGPSecretKeyRing)rIt.next();
   
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

        throws Exception
    {
        SecureRandom rand = new SecureRandom();

        // Read the secret key rings
        PGPSecretKeyRingCollection privRings = new PGPSecretKeyRingCollection(
                                                         new ByteArrayInputStream(rewrapKey));

        Iterator rIt = privRings.getKeyRings();

        if (rIt.hasNext())
        {
            PGPSecretKeyRing pgpPriv = (PGPSecretKeyRing)rIt.next();
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

    private void testSecretKeyRingWithPersonalCertificate()
        throws Exception
    {
        checkSecretKeyRingWithPersonalCertificate(secWithPersonalCertificate);
        PGPSecretKeyRingCollection secRing = new PGPSecretKeyRingCollection(secWithPersonalCertificate);
        checkSecretKeyRingWithPersonalCertificate(secRing.getEncoded());
    }
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

    }

    private void checkSecretKeyRingWithPersonalCertificate(byte[] keyRing)
        throws Exception
    {
        PGPSecretKeyRingCollection secCol = new PGPSecretKeyRingCollection(keyRing);


        int count = 0;

        for (Iterator rIt = secCol.getKeyRings(); rIt.hasNext();)
        {
            PGPSecretKeyRing ring = (PGPSecretKeyRing)rIt.next();

            for (Iterator it = ring.getExtraPublicKeys(); it.hasNext();)
            {
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

            // find the secret key
            //
            Iterator                    it = enc.getEncryptedDataObjects();
            PGPPrivateKey               sKey = null;
            PGPPublicKeyEncryptedData   pbe = null;
            PGPSecretKeyRingCollection  pgpSec = new PGPSecretKeyRingCollection(
                PGPUtil.getDecoderStream(keyIn));                                                                
           
            while (sKey == null && it.hasNext())
            {
                pbe = (PGPPublicKeyEncryptedData)it.next();
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

        if (count != 1)
        {
            fail("wrong number of public keyrings on case-insensitive partial match");
        }
       
        PGPSecretKeyRingCollection    secretRings = new PGPSecretKeyRingCollection(sec1);

        rIt = secretRings.getKeyRings();
        count = 0;
       
        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();
               
                pk.getSignatures();
               
                byte[] pkBytes = pk.getEncoded();
               
                PGPPublicKeyRing  pkR = new PGPPublicKeyRing(pkBytes);
            }
           
            if (keyCount != 2)
            {
                fail("wrong number of secret keys");
            }
        }
       
        if (count != 1)
        {
            fail("wrong number of secret keyrings");
        }
       
        //
        // exact match
        //
        rIt = secretRings.getKeyRings("test (Test key) <test@ubicall.com>");
        count = 0;
        while (rIt.hasNext())
        {
            count++;
            rIt.next();
        }
       
        if (count != 1)
        {
            fail("wrong number of secret keyrings on exact match");
        }
       
        //
        // partial match 1 expected
        //
        rIt = secretRings.getKeyRings("test", true);
        count = 0;
        while (rIt.hasNext())
        {
            count++;
            rIt.next();
        }
       
        if (count != 1)
        {
            fail("wrong number of secret keyrings on partial match 1");
        }
       
        //
        // exact match 0 expected
        //
        rIt = secretRings.getKeyRings("test", false);
        count = 0;
        while (rIt.hasNext())
        {
            count++;
            rIt.next();
        }
       
        if (count != 0)
        {
            fail("wrong number of secret keyrings on partial match 0");
        }

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

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

            // find the secret key
            //
            Iterator                    it = enc.getEncryptedDataObjects();
            PGPPrivateKey               sKey = null;
            PGPPublicKeyEncryptedData   pbe = null;
            PGPSecretKeyRingCollection  pgpSec = new PGPSecretKeyRingCollection(
                PGPUtil.getDecoderStream(keyIn));

            while (sKey == null && it.hasNext())
            {
                pbe = (PGPPublicKeyEncryptedData)it.next();
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

     * @throws IOException on a problem with using the input stream.
     * @throws PGPException if there is an issue parsing the input stream.
     */
    static PGPSecretKey readSecretKey(InputStream input) throws IOException, PGPException
    {
        PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
            PGPUtil.getDecoderStream(input));

        //
        // 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.
        //

        Iterator keyRingIter = pgpSec.getKeyRings();
        while (keyRingIter.hasNext())
        {
            PGPSecretKeyRing keyRing = (PGPSecretKeyRing)keyRingIter.next();

            Iterator keyIter = keyRing.getSecretKeys();
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

   
    private PGPSecretKey readSecretKey(
        InputStream    in)
        throws IOException, PGPException
    {
        PGPSecretKeyRingCollection        pgpSec = new PGPSecretKeyRingCollection(in);

        PGPSecretKey    key = null;

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

        while (key == null && rIt.hasNext())
        {
            PGPSecretKeyRing    kRing = (PGPSecretKeyRing)rIt.next();
            Iterator            kIt = kRing.getSecretKeys();
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

     *
     * @param input the input stream containing the keyring collection
     * @param keyId the 4 bytes identifier of the key
     */
    private PGPSecretKey getSecretKey(InputStream input, String keyId) throws IOException, PGPException {
        PGPSecretKeyRingCollection keyrings = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input));
       
        Iterator rIt = keyrings.getKeyRings();

        while (rIt.hasNext()) {
            PGPSecretKeyRing kRing = (PGPSecretKeyRing) rIt.next();
            Iterator kIt = kRing.getSecretKeys();

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.