OutputStream output = out; if (isArmored) { output = new ArmoredOutputStream(out);
ArmoredOutputStream aOut = new ArmoredOutputStream(out); aOut.beginClearText(digest); aOut.endClearText(); aOut.close();
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();
try (ArmoredOutputStream aOut = new ArmoredOutputStream(buffer)) { aOut.beginClearText(PGPUtil.SHA256); String sigLine = (firstLine ? "" : "\r\n") + line.replaceAll("\\s*$", ""); sigGenerator.update(sigLine.getBytes(Charsets.UTF_8)); aOut.write((line + "\n").getBytes(Charsets.UTF_8)); firstLine = false; aOut.endClearText();
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(); }
@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; } } }
/** * 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(); }
PGPPublicKey encKey = getPublicKey(getPGPPublicKeyRing()); ByteArrayOutputStream encOut = new ByteArrayOutputStream(); OutputStream out = new ArmoredOutputStream(encOut); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(PGPCompressedDataGenerator.ZIP); ByteArrayOutputStream baosPkr = new ByteArrayOutputStream(); PGPPublicKeyRing pkr = krgen.generatePublicKeyRing(); ArmoredOutputStream armoredStreamPkr = new ArmoredOutputStream(baosPkr); pkr.encode(armoredStreamPkr); armoredStreamPkr.close(); return new String(baosPkr.toByteArray(), Charset.defaultCharset()); ByteArrayOutputStream baosPriv = new ByteArrayOutputStream (); PGPSecretKeyRing skr = krgen.generateSecretKeyRing(); ArmoredOutputStream armoredStreamPriv = new ArmoredOutputStream(baosPriv); skr.encode(armoredStreamPriv); armoredStreamPriv.close(); return new String(baosPriv.toByteArray(), Charset.defaultCharset());
OutputStream output = out; if (isArmored) { output = new ArmoredOutputStream(out);
/** * Wraps with stream that outputs ascii-armored text. */ protected OutputStream armor(OutputStream out) { if (asciiArmored) return new ArmoredOutputStream(out); return null; }
/** * Generates the signature of the given input stream as an ASCII file into the given output stream. */ void sign(InputStream in, OutputStream signatureOutput) throws PGPException, IOException, GeneralSecurityException { BCPGOutputStream bOut = new BCPGOutputStream(new ArmoredOutputStream(signatureOutput)); sign(in).encode(bOut); bOut.close(); }
public Content getPublicKey() throws IOException, PGPException { PGPSecretKey signKey = readSecretKey(); PGPPublicKey publicKey = signKey.getPublicKey(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try (BCPGOutputStream os = new BCPGOutputStream(new ArmoredOutputStream(buffer))) { publicKey.encode(os); } return new Content(new BytesPayload(buffer.toByteArray(), AptMimeTypes.PUBLICKEY)); }
public void signEncryptMessage(InputStream in, OutputStream out, String name) throws IOException, PGPException, SignatureException { out = new ArmoredOutputStream(out); PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SYMM_ALG).setWithIntegrityPacket(true).setSecureRandom(rand).setProvider(PROVIDER)); encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(keys.get(name)).setProvider(PROVIDER)); OutputStream encryptedOut = encGen.open(out, new byte[BUFFER_SIZE]); OutputStream compressedData = new PGPCompressedDataGenerator(COMP_ALG).open(encryptedOut); PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(kp.getPrivateKey().getPublicKeyPacket().getAlgorithm(), HASH_ALG).setProvider(PROVIDER)); sGen.init(PGPSignature.BINARY_DOCUMENT, kp.getPrivateKey()); sGen.generateOnePassVersion(false).encode(compressedData); OutputStream finalOut = new PGPLiteralDataGenerator().open(compressedData, PGPLiteralData.BINARY, "", new Date(), new byte[BUFFER_SIZE]); byte[] buf = new byte[BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { finalOut.write(buf, 0, len); sGen.update(buf, 0, len); } in.close(); finalOut.close(); sGen.generate().encode(compressedData); compressedData.close(); encryptedOut.close(); out.close(); }
out = new BCPGOutputStream(new ArmoredOutputStream(new FileOutputStream(dest)));
out = new ArmoredOutputStream(out);
out = new ArmoredOutputStream(out);
out = new FileOutputStream(fileNameOut); if (armoredOutput) { out = new ArmoredOutputStream(out);
OutputStream output = out; if (isArmored) { output = new ArmoredOutputStream(out);
throws IOException, NoSuchProviderException, PGPException { if (armor) { out = new ArmoredOutputStream(out);
OutputStream out = encOut; if (armor) { out = new ArmoredOutputStream(out);