Examples of PGPSecretKeyRingCollection


Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

    }

    @Deprecated
    private static PGPPrivateKey findPrivateKey(InputStream keyringInput, InputStream encryptedInput, String passphrase,
            PGPPassphraseAccessor passphraseAccessor, String provider) throws IOException, PGPException, NoSuchProviderException {
        PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(keyringInput));
        PGPObjectFactory factory = new PGPObjectFactory(PGPUtil.getDecoderStream(encryptedInput));
        PGPEncryptedDataList enc;
        Object o = factory.nextObject();
        if (o == null) {
            throw new PGPException("Provided input is not encrypted.");
        }
        if (o instanceof PGPEncryptedDataList) {
            enc = (PGPEncryptedDataList) o;
        } else {
            enc = (PGPEncryptedDataList) factory.nextObject();
        }
        encryptedInput.reset(); // nextObject() method reads from the InputStream, so rewind it!
        Iterator<?> encryptedDataObjects = enc.getEncryptedDataObjects();
        PGPPrivateKey privateKey = null;
        PGPPublicKeyEncryptedData encryptedData = null;
        while (privateKey == null && encryptedDataObjects.hasNext()) {
            encryptedData = (PGPPublicKeyEncryptedData) encryptedDataObjects.next();
            PGPSecretKey pgpSecKey = pgpSec.getSecretKey(encryptedData.getKeyID());
            if (pgpSecKey != null) {
                if (passphrase == null && passphraseAccessor != null) {
                    // get passphrase from accessor
                    @SuppressWarnings("unchecked")
                    Iterator<String> userIDs = pgpSecKey.getUserIDs();
                    while (passphrase == null && userIDs.hasNext()) {
                        passphrase = passphraseAccessor.getPassphrase(userIDs.next());
                    }
                }
                privateKey = pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(provider).build(
                        passphrase.toCharArray()));
            }
        }
        if (privateKey == null && pgpSec.size() > 0 && encryptedData != null) {
            throw new PGPException("Provided input is encrypted with unknown pair of keys.");
        }
        return privateKey;
    }
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

        return findSecretKey(context, keychainFilename, secKeyRing, passphrase, null, provider);
    }

    private static List<PGPSecretKeyAndPrivateKeyAndUserId> findSecretKeysWithPrivateKeyAndUserId(InputStream keyringInput,
            Map<String, String> sigKeyUserId2Password, String provider) throws IOException, PGPException, NoSuchProviderException {
        PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(keyringInput));
        return findSecretKeysWithPrivateKeyAndUserId(sigKeyUserId2Password, provider, pgpSec);
    }
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

    }

    static PGPSecretKey readSecretKey() throws Exception {
        InputStream input = new ByteArrayInputStream(getSecKeyRing());
        PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input));

        @SuppressWarnings("rawtypes")
        Iterator keyRingIter = pgpSec.getKeyRings();
        while (keyRingIter.hasNext()) {
            PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();

            @SuppressWarnings("rawtypes")
            Iterator keyIter = keyRing.getSecretKeys();
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

    }

    @SuppressWarnings("unchecked")
    public static PGPPrivateKey findPrivateKey(CamelContext context, InputStream input, String userid, String passphrase) throws IOException,
            PGPException, NoSuchProviderException {
        PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input));

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

            Iterator<PGPSecretKey> keyIter = (Iterator<PGPSecretKey>) keyRing.getSecretKeys();
            while (keyIter.hasNext()) {
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

    }

    private void readPrivateKeyBundle() throws Exception
    {
        InputStream in = IOUtils.getResourceAsStream(getSecretKeyRingFileName(), getClass());
        PGPSecretKeyRingCollection collection = new PGPSecretKeyRingCollection(in);
        in.close();
        secretKey = collection.getSecretKey(Long.valueOf(getSecretAliasId()));
       
        if (secretKey == null)
        {
            StringBuilder message = new StringBuilder();
            message.append('\n');
            Iterator iterator = collection.getKeyRings();
            while (iterator.hasNext())
            {
                PGPSecretKeyRing ring = (PGPSecretKeyRing) iterator.next();
                Iterator secretKeysIterator = ring.getSecretKeys();
                while (secretKeysIterator.hasNext())
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

        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();
   
View Full Code Here

Examples of org.bouncycastle.openpgp.PGPSecretKeyRingCollection

        if (count != 1)
        {
            fail("wrong number of public keyrings");
        }
       
        PGPSecretKeyRingCollection    secretRings = new PGPSecretKeyRingCollection(sec3);

        rIt = secretRings.getKeyRings();
        count = 0;
       
        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

    }
   
    public void test4()
        throws Exception
    {
        PGPSecretKeyRingCollection    secretRings = new PGPSecretKeyRingCollection(sec4);

        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

        if (noIDEA())
        {
            return;
        }

        PGPSecretKeyRingCollection    secretRings = new PGPSecretKeyRingCollection(sec5);

        rIt = secretRings.getKeyRings();
        count = 0;
       
        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

        if (count != 2)
        {
            fail("wrong number of public keyrings");
        }
       
        PGPSecretKeyRingCollection    secretRings = new PGPSecretKeyRingCollection(sec8);

        rIt = secretRings.getKeyRings();
        count = 0;
       
        encRing = secretRings.getEncoded();
       
        secretRings = new PGPSecretKeyRingCollection(encRing);
       
        while (rIt.hasNext())
        {
            PGPSecretKeyRing         pgpSec = (PGPSecretKeyRing)rIt.next();
   
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.