List of usage examples for org.bouncycastle.bcpg ArmoredOutputStream flush
public void flush() throws IOException
From source file:de.softwareforge.pgpsigner.key.PublicKey.java
License:Apache License
public byte[] getArmor() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ArmoredOutputStream aos = null; try {/* w w w. ja v a2 s . c om*/ aos = new ArmoredOutputStream(baos); pgpPublicKey.encode(aos); aos.flush(); } finally { IOUtils.closeQuietly(aos); } return baos.toByteArray(); }
From source file:org.pgptool.gui.encryption.implpgp.EncryptionServicePgpImpl.java
License:Open Source License
@Override public String encryptText(String sourceText, Collection<Key> recipients) { try {/*from w w w.jav a 2s . co m*/ PGPEncryptedDataGenerator dataGenerator = buildEncryptedDataGenerator( buildKeysListForEncryption(recipients)); SourceInfo encryptionSourceInfo = new SourceInfo("text.asc", sourceText.length(), System.currentTimeMillis()); ByteArrayOutputStream pOut = new ByteArrayOutputStream(); ByteArrayInputStream pIn = new ByteArrayInputStream(sourceText.getBytes("UTF-8")); ArmoredOutputStream armoredOut = new ArmoredOutputStream(pOut); doEncryptFile(pIn, encryptionSourceInfo, armoredOut, dataGenerator, null, PGPLiteralData.BINARY); pIn.close(); armoredOut.flush(); armoredOut.close(); return pOut.toString(); } catch (Throwable t) { throw new RuntimeException("Encryption failed", t); } }