List of usage examples for org.bouncycastle.openpgp PGPPublicKeyRingCollection contains
public boolean contains(byte[] fingerprint) throws PGPException
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 w w . j av a 2 s .c o 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:org.jivesoftware.smackx.ox.store.abstr.AbstractOpenPgpKeyStore.java
License:Apache License
@Override public void deletePublicKeyRing(BareJid owner, OpenPgpV4Fingerprint fingerprint) throws IOException, PGPException { PGPPublicKeyRingCollection publicKeyRings = getPublicKeysOf(owner); if (publicKeyRings.contains(fingerprint.getKeyId())) { publicKeyRings = PGPPublicKeyRingCollection.removePublicKeyRing(publicKeyRings, publicKeyRings.getPublicKeyRing(fingerprint.getKeyId())); if (!publicKeyRings.iterator().hasNext()) { publicKeyRings = null;/*from ww w . j a v a 2s .c om*/ } this.publicKeyRingCollections.put(owner, publicKeyRings); writePublicKeysOf(owner, publicKeyRings); } }