/** * Close the encrypted output writers. * @throws IOException - stream handling had a problem */ public void close() throws IOException { // close the literal output if (literalOut != null) literalOut.close(); // close the compressor if (compressedOut != null) compressedOut.close(); // close the encrypted output if (encryptedOut != null) encryptedOut.close(); // close the armored output if (armoredOutputStream != null) armoredOutputStream.close(); }
@Override public void close() throws IOException { if (!isClosed) { encryptionDataStream.flush(); encryptionDataStream.close(); encryptionDataStreamGenerator.close(); if (isDoSign) { try { signatureGenerator.generate().encode(compressionStream); // NOPMD: Demeter (BC API) } catch (PGPException e) { throw new IOException(e); } } compressionStreamGenerator.close(); outerEncryptionStream.flush(); outerEncryptionStream.close(); if (armoredOutputStream != null) { armoredOutputStream.flush(); armoredOutputStream.close(); } isClosed = true; } } }
PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(skey.getPublicKey().getAlgorithm(), PGPUtil.SHA256).setProvider("BC")); PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator(); sGen.init(PGPSignature.CANONICAL_TEXT_DOCUMENT, prKey); Iterator userIDs = skey.getPublicKey().getUserIDs(); if (it.hasNext()) { spGen.setSignerUserID(false, (String)userIDs.next()); sGen.setHashedSubpackets(spGen.generate()); } ArmoredOutputStream aos = new ArmoredOutputStream(baos); aos.beginClearText(PGPUtil.SHA256); sGen.update(dataBytes); aos.write(dataBytes); aos.endClearText(); BCPGOutputStream bOut = new BCPGOutputStream(aos); sGen.generate().encode(bOut); aos.flush(); aos.close();
public void asciiArmor(Long keyID, InputStream publicKeyRingStream, OutputStream armoredOutputStream) throws PGPException, IOException { PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream(publicKeyRingStream), new JcaKeyFingerprintCalculator()); PGPPublicKey publicKey = findMatchingPublicKey(pgpPub, keyID); ArmoredOutputStream armored = new ArmoredOutputStream(armoredOutputStream); publicKey.encode(armored); armored.close(); }
ArmoredOutputStream armoredStreamPkr = new ArmoredOutputStream(baosPkr); pkr.encode(armoredStreamPkr); armoredStreamPkr.close(); return new String(baosPkr.toByteArray(), Charset.defaultCharset()); ArmoredOutputStream armoredStreamPriv = new ArmoredOutputStream(baosPriv); skr.encode(armoredStreamPriv); armoredStreamPriv.close(); return new String(baosPriv.toByteArray(), Charset.defaultCharset());
aOut.close();