List of usage examples for org.bouncycastle.openpgp PGPPublicKeyRingCollection encode
public void encode(OutputStream outStream) throws IOException
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 {//from ww w .ja va2 s . c om 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.filebased.FileBasedOpenPgpKeyStore.java
License:Apache License
@Override public void writePublicKeysOf(BareJid owner, PGPPublicKeyRingCollection publicKeys) throws IOException { File file = getPublicKeyRingPath(owner); if (publicKeys == null) { FileUtils.maybeDeleteFileOrThrow(file); return;/* ww w.j a v a 2s . com*/ } OutputStream outputStream = null; try { outputStream = FileUtils.prepareFileOutputStream(file); publicKeys.encode(outputStream); } finally { CloseableUtil.maybeClose(outputStream, LOGGER); } }