org.bouncycastle.openpgp.PGPPBEEncryptedData Java Examples

The following examples show how to use org.bouncycastle.openpgp.PGPPBEEncryptedData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GPGFileDecryptor.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * Taking in a file inputstream and a passPhrase, generate a decrypted file inputstream.
 * @param inputStream file inputstream
 * @param passPhrase passPhrase
 * @return
 * @throws IOException
 */
public InputStream decryptFile(InputStream inputStream, String passPhrase) throws IOException {

  PGPEncryptedDataList enc = getPGPEncryptedDataList(inputStream);
  PGPPBEEncryptedData pbe = (PGPPBEEncryptedData) enc.get(0);
  InputStream clear;

  try {
    clear = pbe.getDataStream(new JcePBEDataDecryptorFactoryBuilder(
        new JcaPGPDigestCalculatorProviderBuilder().setProvider(BouncyCastleProvider.PROVIDER_NAME).build())
            .setProvider(BouncyCastleProvider.PROVIDER_NAME).build(passPhrase.toCharArray()));

    JcaPGPObjectFactory pgpFact = new JcaPGPObjectFactory(clear);

    return new LazyMaterializeDecryptorInputStream(pgpFact);
  } catch (PGPException e) {
    throw new IOException(e);
  }
}
 
Example #2
Source File: Decryptor.java    From jpgpj with MIT License 5 votes vote down vote up
/**
 * Decrypts the encrypted data as the returned input stream.
 */
protected InputStream decrypt(PGPPBEEncryptedData data)
        throws IOException, PGPException {
    char[] passphraseChars = getSymmetricPassphraseChars();
    if ((data == null) || Util.isEmpty(passphraseChars))
        throw new DecryptionException("no suitable decryption key found");

    try {
        return data.getDataStream(
            buildSymmetricKeyDecryptor(passphraseChars));
    } catch (PGPDataValidationException e) {
        throw new PassphraseException(
            "incorrect passphrase for symmetric key", e);
    }
}