org.bouncycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator Java Examples

The following examples show how to use org.bouncycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator. 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: GPGFileEncryptor.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * Taking in an input {@link OutputStream} and a passPhrase, return an {@link OutputStream} that can be used to output
 * encrypted output to the input {@link OutputStream}.
 * @param outputStream the output stream to hold the ciphertext {@link OutputStream}
 * @param passPhrase pass phrase
 * @param cipher the symmetric cipher to use for encryption. If null or empty then a default cipher is used.
 * @return {@link OutputStream} to write content to for encryption
 * @throws IOException
 */
public OutputStream encryptFile(OutputStream outputStream, String passPhrase, String cipher) throws IOException {
  try {
    if (Security.getProvider(PROVIDER_NAME) == null) {
      Security.addProvider(new BouncyCastleProvider());
    }

    PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(
        new JcePGPDataEncryptorBuilder(symmetricKeyAlgorithmNameToTag(cipher))
            .setSecureRandom(new SecureRandom())
            .setProvider(PROVIDER_NAME));
    cPk.addMethod(new JcePBEKeyEncryptionMethodGenerator(passPhrase.toCharArray()).setProvider(PROVIDER_NAME));

    OutputStream cOut = cPk.open(outputStream, new byte[BUFFER_SIZE]);

    PGPLiteralDataGenerator literalGen = new PGPLiteralDataGenerator();
    OutputStream _literalOut =
        literalGen.open(cOut, PGPLiteralDataGenerator.BINARY, PAYLOAD_NAME, new Date(), new byte[BUFFER_SIZE]);

    return new ClosingWrapperOutputStream(_literalOut, cOut, outputStream);
  } catch (PGPException e) {
    throw new IOException(e);
  }
}
 
Example #2
Source File: OpenPGPPasswordBasedEncryptor.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void process(InputStream in, OutputStream out) throws IOException {
    try {
        PGPKeyEncryptionMethodGenerator encryptionMethodGenerator = new JcePBEKeyEncryptionMethodGenerator(password).setProvider(provider);
        org.apache.nifi.processors.standard.util.PGPUtil.encrypt(in, out, algorithm, provider, PGPEncryptedData.AES_128, filename, encryptionMethodGenerator);
    } catch (Exception e) {
        throw new ProcessException(e.getMessage());
    }
}
 
Example #3
Source File: OpenPGPPasswordBasedEncryptor.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void process(InputStream in, OutputStream out) throws IOException {
    try {
        PGPKeyEncryptionMethodGenerator encryptionMethodGenerator = new JcePBEKeyEncryptionMethodGenerator(password).setProvider(provider);
        org.apache.nifi.processors.standard.util.PGPUtil.encrypt(in, out, algorithm, provider, cipher, filename, encryptionMethodGenerator);
    } catch (Exception e) {
        throw new ProcessException(e.getMessage());
    }
}