Repository: nifi
Updated Branches:
  refs/heads/master 0690aee45 -> 498b5023c


http://git-wip-us.apache.org/repos/asf/nifi/blob/498b5023/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/OpenPGPPasswordBasedEncryptorTest.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/OpenPGPPasswordBasedEncryptorTest.java
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/OpenPGPPasswordBasedEncryptorTest.java
deleted file mode 100644
index ddd10ba..0000000
--- 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/OpenPGPPasswordBasedEncryptorTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.nifi.processors.standard.util;
-
-import org.apache.commons.codec.binary.Hex;
-import org.apache.nifi.processor.io.StreamCallback;
-import org.apache.nifi.security.util.EncryptionMethod;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.security.Security;
-
-public class OpenPGPPasswordBasedEncryptorTest {
-    private static final Logger logger = 
LoggerFactory.getLogger(OpenPGPPasswordBasedEncryptorTest.class);
-
-    private final File plainFile = new 
File("src/test/resources/TestEncryptContent/text.txt");
-    private final File encryptedFile = new 
File("src/test/resources/TestEncryptContent/text.txt.asc");
-
-    private static final String PASSWORD = "thisIsABadPassword";
-    private static final String LEGACY_PASSWORD = "Hello, World!";
-
-    @BeforeClass
-    public static void setUpOnce() throws Exception {
-        Security.addProvider(new BouncyCastleProvider());
-    }
-
-    @Before
-    public void setUp() throws Exception {
-
-    }
-
-    @After
-    public void tearDown() throws Exception {
-
-    }
-
-    @Test
-    public void testShouldEncryptAndDecrypt() throws Exception {
-        // Arrange
-        final String PLAINTEXT = "This is a plaintext message.";
-        logger.info("Plaintext: {}", PLAINTEXT);
-        InputStream plainStream = new 
java.io.ByteArrayInputStream(PLAINTEXT.getBytes("UTF-8"));
-        OutputStream cipherStream = new ByteArrayOutputStream();
-        OutputStream recoveredStream = new ByteArrayOutputStream();
-
-        // No file, just streams
-        String filename = "tempFile.txt";
-
-        OpenPGPPasswordBasedEncryptor encryptor = new 
OpenPGPPasswordBasedEncryptor(EncryptionMethod.PGP.getAlgorithm(), 
EncryptionMethod.PGP.getProvider(), PASSWORD.toCharArray(), filename);
-
-        StreamCallback encryptionCallback = encryptor.getEncryptionCallback();
-        StreamCallback decryptionCallback = encryptor.getDecryptionCallback();
-
-        // Act
-        encryptionCallback.process(plainStream, cipherStream);
-
-        final byte[] cipherBytes = ((ByteArrayOutputStream) 
cipherStream).toByteArray();
-        logger.info("Encrypted: {}", Hex.encodeHexString(cipherBytes));
-        InputStream cipherInputStream = new ByteArrayInputStream(cipherBytes);
-
-        decryptionCallback.process(cipherInputStream, recoveredStream);
-
-        // Assert
-        byte[] recoveredBytes = ((ByteArrayOutputStream) 
recoveredStream).toByteArray();
-        String recovered = new String(recoveredBytes, "UTF-8");
-        logger.info("Recovered: {}", recovered);
-        assert PLAINTEXT.equals(recovered);
-    }
-
-    @Test
-    public void testShouldDecryptExternalFile() throws Exception {
-        // Arrange
-        byte[] plainBytes = Files.readAllBytes(Paths.get(plainFile.getPath()));
-        final String PLAINTEXT = new String(plainBytes, "UTF-8");
-
-        InputStream cipherStream = new FileInputStream(encryptedFile);
-        OutputStream recoveredStream = new ByteArrayOutputStream();
-
-        // No file, just streams
-        String filename = encryptedFile.getName();
-
-        OpenPGPPasswordBasedEncryptor encryptor = new 
OpenPGPPasswordBasedEncryptor(EncryptionMethod.PGP.getAlgorithm(), 
EncryptionMethod.PGP.getProvider(), LEGACY_PASSWORD.toCharArray(), filename);
-
-        StreamCallback decryptionCallback = encryptor.getDecryptionCallback();
-
-        // Act
-        decryptionCallback.process(cipherStream, recoveredStream);
-
-        // Assert
-        byte[] recoveredBytes = ((ByteArrayOutputStream) 
recoveredStream).toByteArray();
-        String recovered = new String(recoveredBytes, "UTF-8");
-        logger.info("Recovered: {}", recovered);
-        Assert.assertEquals("Recovered text", PLAINTEXT, recovered);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi/blob/498b5023/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/crypto/OpenPGPKeyBasedEncryptorTest.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/crypto/OpenPGPKeyBasedEncryptorTest.java
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/crypto/OpenPGPKeyBasedEncryptorTest.java
new file mode 100644
index 0000000..b4cd2e3
--- /dev/null
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/crypto/OpenPGPKeyBasedEncryptorTest.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.standard.util.crypto;
+
+import org.apache.commons.codec.binary.Hex;
+import org.apache.nifi.processor.io.StreamCallback;
+import org.apache.nifi.security.util.EncryptionMethod;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.security.Security;
+
+public class OpenPGPKeyBasedEncryptorTest {
+    private static final Logger logger = 
LoggerFactory.getLogger(OpenPGPKeyBasedEncryptorTest.class);
+
+    private final File plainFile = new 
File("src/test/resources/TestEncryptContent/text.txt");
+    private final File unsignedFile = new 
File("src/test/resources/TestEncryptContent/text.txt.unsigned.gpg");
+    private final File encryptedFile = new 
File("src/test/resources/TestEncryptContent/text.txt.gpg");
+
+    private static final String SECRET_KEYRING_PATH = 
"src/test/resources/TestEncryptContent/secring.gpg";
+    private static final String PUBLIC_KEYRING_PATH = 
"src/test/resources/TestEncryptContent/pubring.gpg";
+    private static final String USER_ID = "NiFi PGP Test Key (Short test key 
for NiFi PGP unit tests) <[email protected]>";
+
+    private static final String PASSWORD = "thisIsABadPassword";
+
+    @BeforeClass
+    public static void setUpOnce() throws Exception {
+        Security.addProvider(new BouncyCastleProvider());
+    }
+
+    @Before
+    public void setUp() throws Exception {
+
+    }
+
+    @After
+    public void tearDown() throws Exception {
+
+    }
+
+    @Test
+    public void testShouldEncryptAndDecrypt() throws Exception {
+        // Arrange
+        final String PLAINTEXT = "This is a plaintext message.";
+        logger.info("Plaintext: {}", PLAINTEXT);
+        InputStream plainStream = new 
ByteArrayInputStream(PLAINTEXT.getBytes("UTF-8"));
+        OutputStream cipherStream = new ByteArrayOutputStream();
+        OutputStream recoveredStream = new ByteArrayOutputStream();
+
+        // No file, just streams
+        String filename = "tempFile.txt";
+
+        // Encryptor does not require password
+        OpenPGPKeyBasedEncryptor encryptor = new OpenPGPKeyBasedEncryptor(
+            EncryptionMethod.PGP.getAlgorithm(), 
EncryptionMethod.PGP.getProvider(), PUBLIC_KEYRING_PATH, USER_ID, new char[0], 
filename);
+        StreamCallback encryptionCallback = encryptor.getEncryptionCallback();
+
+        OpenPGPKeyBasedEncryptor decryptor = new OpenPGPKeyBasedEncryptor(
+            EncryptionMethod.PGP.getAlgorithm(), 
EncryptionMethod.PGP.getProvider(), SECRET_KEYRING_PATH, USER_ID, 
PASSWORD.toCharArray(), filename);
+        StreamCallback decryptionCallback = decryptor.getDecryptionCallback();
+
+        // Act
+        encryptionCallback.process(plainStream, cipherStream);
+
+        final byte[] cipherBytes = ((ByteArrayOutputStream) 
cipherStream).toByteArray();
+        logger.info("Encrypted: {}", Hex.encodeHexString(cipherBytes));
+        InputStream cipherInputStream = new ByteArrayInputStream(cipherBytes);
+
+        decryptionCallback.process(cipherInputStream, recoveredStream);
+
+        // Assert
+        byte[] recoveredBytes = ((ByteArrayOutputStream) 
recoveredStream).toByteArray();
+        String recovered = new String(recoveredBytes, "UTF-8");
+        logger.info("Recovered: {}", recovered);
+        assert PLAINTEXT.equals(recovered);
+    }
+
+    @Test
+    public void testShouldDecryptExternalFile() throws Exception {
+        // Arrange
+        byte[] plainBytes = Files.readAllBytes(Paths.get(plainFile.getPath()));
+        final String PLAINTEXT = new String(plainBytes, "UTF-8");
+
+        InputStream cipherStream = new FileInputStream(unsignedFile);
+        OutputStream recoveredStream = new ByteArrayOutputStream();
+
+        // No file, just streams
+        String filename = unsignedFile.getName();
+
+        OpenPGPKeyBasedEncryptor encryptor = new OpenPGPKeyBasedEncryptor(
+            EncryptionMethod.PGP.getAlgorithm(), 
EncryptionMethod.PGP.getProvider(), SECRET_KEYRING_PATH, USER_ID, 
PASSWORD.toCharArray(), filename);
+
+        StreamCallback decryptionCallback = encryptor.getDecryptionCallback();
+
+        // Act
+        decryptionCallback.process(cipherStream, recoveredStream);
+
+        // Assert
+        byte[] recoveredBytes = ((ByteArrayOutputStream) 
recoveredStream).toByteArray();
+        String recovered = new String(recoveredBytes, "UTF-8");
+        logger.info("Recovered: {}", recovered);
+        Assert.assertEquals("Recovered text", PLAINTEXT, recovered);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi/blob/498b5023/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/crypto/OpenPGPPasswordBasedEncryptorTest.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/crypto/OpenPGPPasswordBasedEncryptorTest.java
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/crypto/OpenPGPPasswordBasedEncryptorTest.java
new file mode 100644
index 0000000..5698ea9
--- /dev/null
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/crypto/OpenPGPPasswordBasedEncryptorTest.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.standard.util.crypto;
+
+import org.apache.commons.codec.binary.Hex;
+import org.apache.nifi.processor.io.StreamCallback;
+import org.apache.nifi.security.util.EncryptionMethod;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.security.Security;
+
+public class OpenPGPPasswordBasedEncryptorTest {
+    private static final Logger logger = 
LoggerFactory.getLogger(OpenPGPPasswordBasedEncryptorTest.class);
+
+    private final File plainFile = new 
File("src/test/resources/TestEncryptContent/text.txt");
+    private final File encryptedFile = new 
File("src/test/resources/TestEncryptContent/text.txt.asc");
+
+    private static final String PASSWORD = "thisIsABadPassword";
+    private static final String LEGACY_PASSWORD = "Hello, World!";
+
+    @BeforeClass
+    public static void setUpOnce() throws Exception {
+        Security.addProvider(new BouncyCastleProvider());
+    }
+
+    @Before
+    public void setUp() throws Exception {
+
+    }
+
+    @After
+    public void tearDown() throws Exception {
+
+    }
+
+    @Test
+    public void testShouldEncryptAndDecrypt() throws Exception {
+        // Arrange
+        final String PLAINTEXT = "This is a plaintext message.";
+        logger.info("Plaintext: {}", PLAINTEXT);
+        InputStream plainStream = new 
java.io.ByteArrayInputStream(PLAINTEXT.getBytes("UTF-8"));
+        OutputStream cipherStream = new ByteArrayOutputStream();
+        OutputStream recoveredStream = new ByteArrayOutputStream();
+
+        // No file, just streams
+        String filename = "tempFile.txt";
+
+        OpenPGPPasswordBasedEncryptor encryptor = new 
OpenPGPPasswordBasedEncryptor(EncryptionMethod.PGP.getAlgorithm(), 
EncryptionMethod.PGP.getProvider(), PASSWORD.toCharArray(), filename);
+
+        StreamCallback encryptionCallback = encryptor.getEncryptionCallback();
+        StreamCallback decryptionCallback = encryptor.getDecryptionCallback();
+
+        // Act
+        encryptionCallback.process(plainStream, cipherStream);
+
+        final byte[] cipherBytes = ((ByteArrayOutputStream) 
cipherStream).toByteArray();
+        logger.info("Encrypted: {}", Hex.encodeHexString(cipherBytes));
+        InputStream cipherInputStream = new ByteArrayInputStream(cipherBytes);
+
+        decryptionCallback.process(cipherInputStream, recoveredStream);
+
+        // Assert
+        byte[] recoveredBytes = ((ByteArrayOutputStream) 
recoveredStream).toByteArray();
+        String recovered = new String(recoveredBytes, "UTF-8");
+        logger.info("Recovered: {}", recovered);
+        assert PLAINTEXT.equals(recovered);
+    }
+
+    @Test
+    public void testShouldDecryptExternalFile() throws Exception {
+        // Arrange
+        byte[] plainBytes = Files.readAllBytes(Paths.get(plainFile.getPath()));
+        final String PLAINTEXT = new String(plainBytes, "UTF-8");
+
+        InputStream cipherStream = new FileInputStream(encryptedFile);
+        OutputStream recoveredStream = new ByteArrayOutputStream();
+
+        // No file, just streams
+        String filename = encryptedFile.getName();
+
+        OpenPGPPasswordBasedEncryptor encryptor = new 
OpenPGPPasswordBasedEncryptor(EncryptionMethod.PGP.getAlgorithm(), 
EncryptionMethod.PGP.getProvider(), LEGACY_PASSWORD.toCharArray(), filename);
+
+        StreamCallback decryptionCallback = encryptor.getDecryptionCallback();
+
+        // Act
+        decryptionCallback.process(cipherStream, recoveredStream);
+
+        // Assert
+        byte[] recoveredBytes = ((ByteArrayOutputStream) 
recoveredStream).toByteArray();
+        String recovered = new String(recoveredBytes, "UTF-8");
+        logger.info("Recovered: {}", recovered);
+        Assert.assertEquals("Recovered text", PLAINTEXT, recovered);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi/blob/498b5023/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/salted_128_raw.enc
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/salted_128_raw.enc
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/salted_128_raw.enc
new file mode 100644
index 0000000..d292df7
--- /dev/null
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/salted_128_raw.enc
@@ -0,0 +1 @@
+Salted__!C�6�y5���ސ��}3��$/�s�BA�@���<]t���L�
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi/blob/498b5023/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/unsalted_128_raw.enc
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/unsalted_128_raw.enc
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/unsalted_128_raw.enc
new file mode 100644
index 0000000..8ffe11c
Binary files /dev/null and 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/unsalted_128_raw.enc
 differ

http://git-wip-us.apache.org/repos/asf/nifi/blob/498b5023/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/logback-test.xml
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/logback-test.xml
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/logback-test.xml
index fad019a..15e9255 100644
--- 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/logback-test.xml
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/logback-test.xml
@@ -21,7 +21,7 @@
             <immediateFlush>false</immediateFlush>
         </encoder>
     </appender>
-    
+
     <appender name="TARGET_FILE" 
class="ch.qos.logback.core.rolling.RollingFileAppender">
         <file>target/log.txt</file>
         <rollingPolicy 
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
@@ -36,14 +36,15 @@
             <pattern>%date %level [%thread] %logger{40} %msg%n</pattern>
             <immediateFlush>true</immediateFlush>
         </encoder>
-    </appender>    
+    </appender>
     <!-- valid logging levels: TRACE, DEBUG, INFO, WARN, ERROR -->
     <logger name="org.apache.nifi" level="INFO"/>
-    
+    <logger name="org.apache.nifi.processors.standard.util.crypto" 
level="DEBUG"/>
+
     <!-- Logger for managing logging statements for nifi clusters. -->
     <logger name="org.apache.nifi.cluster" level="INFO"/>
 
-    <!-- 
+    <!--
         Logger for logging HTTP requests received by the web server.  Setting
         log level to 'debug' activates HTTP request logging.
     -->
@@ -57,11 +58,11 @@
 
     <logger name="org.apache.nifi.processors.standard" level="DEBUG"/>
     <logger name="target.file" level="DEBUG" additivity="true">
-        <appender-ref ref="TARGET_FILE" />
+        <appender-ref ref="TARGET_FILE"/>
     </logger>
 
     <root level="INFO">
         <appender-ref ref="CONSOLE"/>
     </root>
-    
+
 </configuration>

http://git-wip-us.apache.org/repos/asf/nifi/blob/498b5023/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_aes.rb
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_aes.rb
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_aes.rb
new file mode 100755
index 0000000..e51dbb7
--- /dev/null
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_aes.rb
@@ -0,0 +1,46 @@
+#!/usr/bin/env ruby
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'openssl'
+
+def bin_to_hex(s)
+  s.each_byte.map { |b| b.to_s(16).rjust(2, '0') }.join
+end
+
+plaintext = "This is a plaintext message."
+puts "Plaintext: #{plaintext}"
+
+cipher = OpenSSL::Cipher.new 'AES-128-CBC'
+cipher.encrypt
+iv = cipher.random_iv
+
+key_len = cipher.key_len
+digest = OpenSSL::Digest::SHA256.new
+key = digest.digest(plaintext)[0..15]
+
+puts ""
+
+puts "  IV: #{bin_to_hex(iv)} #{iv.length}"
+puts " Key: #{bin_to_hex(key)} #{key.length}"
+cipher.key = key
+
+# Now encrypt the data:
+
+encrypted = cipher.update plaintext
+encrypted << cipher.final
+puts "Cipher text length: #{encrypted.length}"
+puts "Cipher text: #{bin_to_hex(encrypted)}"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi/blob/498b5023/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_bcrypt.rb
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_bcrypt.rb
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_bcrypt.rb
new file mode 100755
index 0000000..bcb62ce
--- /dev/null
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_bcrypt.rb
@@ -0,0 +1,62 @@
+#!/usr/bin/env ruby
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'openssl'
+require 'base64'
+
+# Run `$ gem install bcrypt` >= 2.1.4
+require 'bcrypt'
+
+def bin_to_hex(s)
+  s.each_byte.map { |b| b.to_s(16).rjust(2, '0') }.join
+end
+
+plaintext = "This is a plaintext message."
+puts "Plaintext: #{plaintext}"
+
+cipher = OpenSSL::Cipher.new 'AES-128-CBC'
+cipher.encrypt
+iv = cipher.random_iv
+
+password = 'thisIsABadPassword'
+puts "Password: #{password} #{password.length}"
+work_factor = 10
+puts "Work factor: #{work_factor}"
+key_len = cipher.key_len
+digest = OpenSSL::Digest::SHA512.new
+
+puts ""
+
+hash = BCrypt::Password.create(password, :cost => work_factor)
+puts "Hash: #{hash}"
+full_salt = hash.salt
+puts "Full Salt: #{full_salt} #{full_salt.length}"
+
+key = (digest.digest hash)[0..key_len - 1]
+salt = Base64.decode64(hash.salt[7..-1])
+
+puts "Salt: #{bin_to_hex(salt)} #{salt.length}"
+puts "  IV: #{bin_to_hex(iv)} #{iv.length}"
+puts " Key: #{bin_to_hex(key)} #{key.length}"
+cipher.key = key
+
+# Now encrypt the data:
+
+encrypted = cipher.update plaintext
+encrypted << cipher.final
+puts "Cipher text length: #{encrypted.length}"
+puts "Cipher text: #{bin_to_hex(encrypted)}"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi/blob/498b5023/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_pbkdf2.rb
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_pbkdf2.rb
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_pbkdf2.rb
new file mode 100755
index 0000000..3e81609
--- /dev/null
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_pbkdf2.rb
@@ -0,0 +1,52 @@
+#!/usr/bin/env ruby
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'openssl'
+
+def bin_to_hex(s)
+  s.each_byte.map { |b| b.to_s(16).rjust(2, '0') }.join
+end
+
+plaintext = "This is a plaintext message."
+puts "Plaintext: #{plaintext}"
+
+cipher = OpenSSL::Cipher.new 'AES-128-CBC'
+cipher.encrypt
+iv = cipher.random_iv
+
+password = 'thisIsABadPassword'
+puts "Password: #{password} #{password.length}"
+salt = OpenSSL::Random.random_bytes 16
+iterations = 1000
+puts "Iterations: #{iterations}"
+key_len = cipher.key_len
+digest = OpenSSL::Digest::SHA256.new
+
+puts ""
+
+key = OpenSSL::PKCS5.pbkdf2_hmac(password, salt, iterations, key_len, digest)
+puts "Salt: #{bin_to_hex(salt)} #{salt.length}"
+puts "  IV: #{bin_to_hex(iv)} #{iv.length}"
+puts " Key: #{bin_to_hex(key)} #{key.length}"
+cipher.key = key
+
+# Now encrypt the data:
+
+encrypted = cipher.update plaintext
+encrypted << cipher.final
+puts "Cipher text length: #{encrypted.length}"
+puts "Cipher text: #{bin_to_hex(encrypted)}"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi/blob/498b5023/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_scrypt.rb
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_scrypt.rb
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_scrypt.rb
new file mode 100755
index 0000000..1031b45
--- /dev/null
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/openssl_scrypt.rb
@@ -0,0 +1,58 @@
+#!/usr/bin/env ruby
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'openssl'
+require 'base64'
+
+# Run `$ gem install scrypt`
+require 'scrypt'
+
+def bin_to_hex(s)
+  s.each_byte.map { |b| b.to_s(16).rjust(2, '0') }.join
+end
+
+plaintext = "This is a plaintext message."
+puts "Plaintext: #{plaintext}"
+
+cipher = OpenSSL::Cipher.new 'AES-128-CBC'
+cipher.encrypt
+iv = cipher.random_iv
+
+password = 'thisIsABadPassword'
+puts "Password: #{password} #{password.length}"
+cost = SCrypt::Engine.calibrate
+puts "Cost: #{cost} (N$r$p$)"
+key_len = cipher.key_len
+
+puts ""
+
+hash = SCrypt::Password.create(password, :cost => cost, :key_len => key_len, 
:salt_size => 16)
+puts "Hash: #{hash}"
+# These values are already hex-encoded strings unlike the bcrypt and PBKDF2 
examples, so unpack them to binary
+salt = [hash.salt].pack('H*')
+key = [hash.digest].pack('H*')
+puts "Salt: #{bin_to_hex(salt)} #{salt.length}"
+puts "  IV: #{bin_to_hex(iv)} #{iv.length}"
+puts " Key: #{bin_to_hex(key)} #{key.length}"
+cipher.key = key
+
+# Now encrypt the data:
+
+encrypted = cipher.update plaintext
+encrypted << cipher.final
+puts "Cipher text length: #{encrypted.length}"
+puts "Cipher text: #{bin_to_hex(encrypted)}"
\ No newline at end of file

Reply via email to