List of usage examples for org.bouncycastle.openpgp PGPPublicKeyRingCollection addPublicKeyRing
public static PGPPublicKeyRingCollection addPublicKeyRing(PGPPublicKeyRingCollection ringCollection, PGPPublicKeyRing publicKeyRing)
From source file:alpha.offsync.security.OpenPGPSecurityUtility.java
License:Apache License
@Override public void importCryptographyMetadata(final InputStream input) { OpenPGPSecurityUtility.LOGGER.info("Importing cryptography metadata"); try {/* w ww.j a v a2s . co m*/ PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream(new FileInputStream(this.publicKeyRing))); final PGPPublicKeyRingCollection pgpPubIncoming = new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream(input)); PGPPublicKeyRing ppKr; final Iterator<PGPPublicKeyRing> it = pgpPubIncoming.getKeyRings(); while (it.hasNext()) { ppKr = it.next(); if (!pgpPub.contains(ppKr.getPublicKey().getKeyID())) { pgpPub = PGPPublicKeyRingCollection.addPublicKeyRing(pgpPub, ppKr); } } pgpPub.encode(new FileOutputStream(new File(this.publicKeyRing.getAbsolutePath()))); } catch (final FileNotFoundException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } catch (final PGPException e) { e.printStackTrace(); } }
From source file:com.geekcommune.identity.EncryptionUtil.java
License:Open Source License
public PGPPublicKeyRingCollection readPublicKeyRing(String baseDir) throws FileNotFoundException, IOException, PGPException { PGPPublicKeyRingCollection pubRings = null; PGPPublicKeyRing pgpPub = null;/* w ww .j a v a 2s . co m*/ // directory that contains all the .asc files File dir = new File(baseDir + "/KeyRings/Public"); // list all the files String[] children = dir.list(); if (children == null) { // Either dir does not exist or is not a directory } else { for (int i = 0; i < children.length; i++) { String filename = children[i]; log.info("File Name (.asc) " + "(" + i + ")" + " = " + filename); PGPPublicKeyRingCollection tmpKeyRingCollection = readPublicKeyRingCollection( new File(dir, filename)); if (pubRings == null) { // read the first .asc file and create the // PGPPublicKeyRingCollection to hold all the other key // rings pubRings = tmpKeyRingCollection; } else { PGPPublicKeyRingCollection otherKeyRings = tmpKeyRingCollection; @SuppressWarnings("unchecked") Iterator<PGPPublicKeyRing> rIt = otherKeyRings.getKeyRings(); while (rIt.hasNext()) { pgpPub = rIt.next(); } //TODO bobby doesn't this belong inside the loop? // copy the key ring to PGPPublicKeyCollection pubRings pubRings = PGPPublicKeyRingCollection.addPublicKeyRing(pubRings, pgpPub); } } // end of for // size should equal the number of the .asc files log.debug("Collection size = " + pubRings.size()); } // end of else return pubRings; }
From source file:de.jtheuer.diki.lib.pgp.PGPHandler.java
License:Open Source License
/** * Adds a new public key to the current keyring * @param key/* w ww. j av a 2 s.com*/ * @throws IOException */ public void addPublicKey(PGPPublicKeyRing key) { keyring = PGPPublicKeyRingCollection.addPublicKeyRing(keyring, key); }
From source file:org.jivesoftware.smackx.ox.OpenPgpContact.java
License:Apache License
/** * Return any announced public keys. This is the set returned by {@link #getAnyPublicKeys()} with non-announced * keys and keys which lack a user-id with the contacts jid removed. * * @return announced keys of the contact * * @throws IOException IO is dangerous/*from ww w. ja v a 2 s.c om*/ * @throws PGPException PGP is brittle */ public PGPPublicKeyRingCollection getAnnouncedPublicKeys() throws IOException, PGPException { PGPPublicKeyRingCollection anyKeys = getAnyPublicKeys(); Map<OpenPgpV4Fingerprint, Date> announced = store.getAnnouncedFingerprintsOf(jid); BareJidUserId.PubRingSelectionStrategy userIdFilter = new BareJidUserId.PubRingSelectionStrategy(); PGPPublicKeyRingCollection announcedKeysCollection = null; for (OpenPgpV4Fingerprint announcedFingerprint : announced.keySet()) { PGPPublicKeyRing ring = anyKeys.getPublicKeyRing(announcedFingerprint.getKeyId()); if (ring == null) continue; ring = BCUtil.removeUnassociatedKeysFromKeyRing(ring, ring.getPublicKey(announcedFingerprint.getKeyId())); if (!userIdFilter.accept(getJid(), ring)) { LOGGER.log(Level.WARNING, "Ignore key " + Long.toHexString(ring.getPublicKey().getKeyID()) + " as it lacks the user-id \"xmpp" + getJid().toString() + "\""); continue; } if (announcedKeysCollection == null) { announcedKeysCollection = new PGPPublicKeyRingCollection(Collections.singleton(ring)); } else { announcedKeysCollection = PGPPublicKeyRingCollection.addPublicKeyRing(announcedKeysCollection, ring); } } return announcedKeysCollection; }
From source file:org.jivesoftware.smackx.ox.store.abstr.AbstractOpenPgpKeyStore.java
License:Apache License
@Override public void importPublicKey(BareJid owner, PGPPublicKeyRing publicKeys) throws IOException, PGPException, MissingUserIdOnKeyException { if (!new BareJidUserId.PubRingSelectionStrategy().accept(owner, publicKeys)) { throw new MissingUserIdOnKeyException(owner, new OpenPgpV4Fingerprint(publicKeys)); }/* w w w .j ava2 s . c om*/ PGPPublicKeyRing importKeys = BCUtil.removeUnassociatedKeysFromKeyRing(publicKeys, publicKeys.getPublicKey()); PGPPublicKeyRingCollection publicKeyRings = getPublicKeysOf(owner); try { if (publicKeyRings != null) { publicKeyRings = PGPPublicKeyRingCollection.addPublicKeyRing(publicKeyRings, importKeys); } else { publicKeyRings = BCUtil.keyRingsToKeyRingCollection(importKeys); } } catch (IllegalArgumentException e) { LOGGER.log(Level.INFO, "Skipping public key ring " + Long.toHexString(importKeys.getPublicKey().getKeyID()) + " as it is already in the key ring of " + owner.toString()); } this.publicKeyRingCollections.put(owner, publicKeyRings); writePublicKeysOf(owner, publicKeyRings); }
From source file:uk.co.platosys.dinigma.Lock.java
License:GNU General Public License
/** * Adds a Lock to this lock, concatenating the two. Material locked with the * resulting concatenated Lock can be unlocked with *any* of the corresponding * Keys.//ww w . j a va 2s .c om * @param lock the Lock to be added to this Lock * @return a Lock which can be unlocked by the keys corresponding to either Lock. */ public Lock addLock(Lock lock, boolean inclusive) throws MinigmaException { if (inclusive) { throw new MinigmaException("inclusive Lock concatenation not yet implemented"); } try { Iterator<PGPPublicKeyRing> keys = lock.getKeys(); while (keys.hasNext()) { PGPPublicKeyRing key = keys.next(); long keyID = key.getPublicKey().getKeyID(); if (!(publicKeys.contains(keyID))) { PGPPublicKeyRingCollection.addPublicKeyRing(publicKeys, key); } } } catch (Exception x) { throw new MinigmaException("Error concatenating Lock", x); } return this; }