out = new BCPGOutputStream(new ArmoredOutputStream(new FileOutputStream(dest)));
/** * 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(); }
} finally { if (lOut != null) try { lOut.close(); } catch (IOException e) {} if (bOut != null) try { bOut.close(); } catch (IOException e) {} if (out != null) try { out.close(); } catch (IOException e) {} if (fIn != null) try { fIn.close(); } catch (IOException e) {}
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 byte[] signExternal(String input) throws IOException, PGPException { PGPSecretKey signKey = readSecretKey(); PGPPrivateKey privKey = signKey.extractPrivateKey( new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(config.passphrase.toCharArray())); PGPSignatureGenerator sigGenerator = new PGPSignatureGenerator( new JcaPGPContentSignerBuilder(signKey.getPublicKey().getAlgorithm(), PGPUtil.SHA256).setProvider("BC")); sigGenerator.init(PGPSignature.BINARY_DOCUMENT, privKey); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try (ArmoredOutputStream aOut = new ArmoredOutputStream(buffer)) { BCPGOutputStream bOut = new BCPGOutputStream(aOut); sigGenerator.update(input.getBytes(Charsets.UTF_8)); sigGenerator.generate().encode(bOut); } return buffer.toByteArray(); }
private static void createSignature( String fileName, InputStream keyIn, OutputStream out, char[] pass, boolean armor) throws GeneralSecurityException, IOException, PGPException { if (armor) { out = new ArmoredOutputStream(out); } PGPSecretKey pgpSec = PGPExampleUtil.readSecretKey(keyIn); PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pass)); PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(), PGPUtil.SHA1).setProvider("BC")); sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey); BCPGOutputStream bOut = new BCPGOutputStream(out); InputStream fIn = new BufferedInputStream(new FileInputStream(fileName)); int ch; while ((ch = fIn.read()) >= 0) { sGen.update((byte) ch); } fIn.close(); sGen.generate().encode(bOut); if (armor) { out.close(); } }
BCPGOutputStream bOut = new BCPGOutputStream(aOut); sigGenerator.generate().encode(bOut);
BCPGOutputStream bOut = new BCPGOutputStream(aOut);
PGPCompressedData.ZLIB); BCPGOutputStream bOut = new BCPGOutputStream(cGen.open(out));
compressionStream = new BCPGOutputStream( compressionStreamGenerator.open(outerEncryptionStream));