Search in sources :

Example 6 with KeyDerivationFunction

use of org.apache.nifi.security.util.KeyDerivationFunction in project nifi by apache.

the class TestEncryptContent method testShouldDecryptOpenSSLRawUnsalted.

@Test
public void testShouldDecryptOpenSSLRawUnsalted() throws IOException {
    // Arrange
    Assume.assumeTrue("Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.", PasswordBasedEncryptor.supportsUnlimitedStrength());
    final TestRunner testRunner = TestRunners.newTestRunner(new EncryptContent());
    final String password = "thisIsABadPassword";
    final EncryptionMethod method = EncryptionMethod.MD5_256AES;
    final KeyDerivationFunction kdf = KeyDerivationFunction.OPENSSL_EVP_BYTES_TO_KEY;
    testRunner.setProperty(EncryptContent.PASSWORD, password);
    testRunner.setProperty(EncryptContent.KEY_DERIVATION_FUNCTION, kdf.name());
    testRunner.setProperty(EncryptContent.ENCRYPTION_ALGORITHM, method.name());
    testRunner.setProperty(EncryptContent.MODE, EncryptContent.DECRYPT_MODE);
    // Act
    testRunner.enqueue(Paths.get("src/test/resources/TestEncryptContent/unsalted_raw.enc"));
    testRunner.clearTransferState();
    testRunner.run();
    // Assert
    testRunner.assertAllFlowFilesTransferred(EncryptContent.REL_SUCCESS, 1);
    testRunner.assertQueueEmpty();
    MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(EncryptContent.REL_SUCCESS).get(0);
    logger.info("Decrypted contents (hex): {}", Hex.encodeHexString(flowFile.toByteArray()));
    logger.info("Decrypted contents: {}", new String(flowFile.toByteArray(), "UTF-8"));
    // Assert
    flowFile.assertContentEquals(new File("src/test/resources/TestEncryptContent/plain.txt"));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) KeyDerivationFunction(org.apache.nifi.security.util.KeyDerivationFunction) TestRunner(org.apache.nifi.util.TestRunner) EncryptionMethod(org.apache.nifi.security.util.EncryptionMethod) File(java.io.File) MockFlowFile(org.apache.nifi.util.MockFlowFile) Test(org.junit.Test)

Aggregations

KeyDerivationFunction (org.apache.nifi.security.util.KeyDerivationFunction)6 EncryptionMethod (org.apache.nifi.security.util.EncryptionMethod)4 ArrayList (java.util.ArrayList)3 File (java.io.File)2 MockFlowFile (org.apache.nifi.util.MockFlowFile)2 TestRunner (org.apache.nifi.util.TestRunner)2 Test (org.junit.Test)2 DecoderException (org.apache.commons.codec.DecoderException)1 AllowableValue (org.apache.nifi.components.AllowableValue)1 ValidationResult (org.apache.nifi.components.ValidationResult)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1 ComponentLog (org.apache.nifi.logging.ComponentLog)1 ProcessException (org.apache.nifi.processor.exception.ProcessException)1 StreamCallback (org.apache.nifi.processor.io.StreamCallback)1 KeyedEncryptor (org.apache.nifi.security.util.crypto.KeyedEncryptor)1 OpenPGPKeyBasedEncryptor (org.apache.nifi.security.util.crypto.OpenPGPKeyBasedEncryptor)1 OpenPGPPasswordBasedEncryptor (org.apache.nifi.security.util.crypto.OpenPGPPasswordBasedEncryptor)1 PasswordBasedEncryptor (org.apache.nifi.security.util.crypto.PasswordBasedEncryptor)1 StopWatch (org.apache.nifi.util.StopWatch)1