@Override public void process(final InputStream in, final OutputStream out) throws IOException { // Initialize cipher provider KeyedCipherProvider cipherProvider = (KeyedCipherProvider) CipherProviderFactory.getCipherProvider(KeyDerivationFunction.NONE); // Generate cipher try { Cipher cipher; // The IV could have been set by the constructor, but if not, read from the cipher stream if (iv.length == 0) { iv = cipherProvider.readIV(in); } cipher = cipherProvider.getCipher(encryptionMethod, key, iv, false); CipherUtility.processStreams(cipher, in, out); } catch (Exception e) { throw new ProcessException(e); } } }
@Override public void process(final InputStream in, final OutputStream out) throws IOException { // Initialize cipher provider KeyedCipherProvider cipherProvider = (KeyedCipherProvider) CipherProviderFactory.getCipherProvider(KeyDerivationFunction.NONE); // Generate cipher try { Cipher cipher = cipherProvider.getCipher(encryptionMethod, key, iv, true); cipherProvider.writeIV(cipher.getIV(), out); CipherUtility.processStreams(cipher, in, out); } catch (Exception e) { throw new ProcessException(e); } } }
cipher = cipherProvider.getCipher(encryptionMethod, new String(password.getPassword()), salt, keyLength, false); CipherUtility.processStreams(cipher, in, out); } catch (Exception e) { throw new ProcessException(e);
@Override public void process(final InputStream in, final OutputStream out) throws IOException { // Initialize cipher provider PBECipherProvider cipherProvider = (PBECipherProvider) CipherProviderFactory.getCipherProvider(kdf); // Generate salt byte[] salt; // NiFi legacy code determined the salt length based on the cipher block size if (cipherProvider instanceof org.apache.nifi.security.util.crypto.NiFiLegacyCipherProvider) { salt = ((org.apache.nifi.security.util.crypto.NiFiLegacyCipherProvider) cipherProvider).generateSalt(encryptionMethod); } else { salt = cipherProvider.generateSalt(); } // Write to output stream cipherProvider.writeSalt(salt, out); // Determine necessary key length int keyLength = CipherUtility.parseKeyLengthFromAlgorithm(encryptionMethod.getAlgorithm()); // Generate cipher try { Cipher cipher = cipherProvider.getCipher(encryptionMethod, new String(password.getPassword()), salt, keyLength, true); // Write IV if necessary if (cipherProvider instanceof RandomIVPBECipherProvider) { ((RandomIVPBECipherProvider) cipherProvider).writeIV(cipher.getIV(), out); } CipherUtility.processStreams(cipher, in, out); } catch (Exception e) { throw new ProcessException(e); } } }
@Override public void process(final InputStream in, final OutputStream out) throws IOException { // Initialize cipher provider KeyedCipherProvider cipherProvider = (KeyedCipherProvider) CipherProviderFactory.getCipherProvider(KeyDerivationFunction.NONE); // Generate cipher try { Cipher cipher; // The IV could have been set by the constructor, but if not, read from the cipher stream if (iv.length == 0) { iv = cipherProvider.readIV(in); } cipher = cipherProvider.getCipher(encryptionMethod, key, iv, false); CipherUtility.processStreams(cipher, in, out); } catch (Exception e) { throw new ProcessException(e); } } }
@Override public void process(final InputStream in, final OutputStream out) throws IOException { // Initialize cipher provider KeyedCipherProvider cipherProvider = (KeyedCipherProvider) CipherProviderFactory.getCipherProvider(KeyDerivationFunction.NONE); // Generate cipher try { Cipher cipher = cipherProvider.getCipher(encryptionMethod, key, iv, true); cipherProvider.writeIV(cipher.getIV(), out); CipherUtility.processStreams(cipher, in, out); } catch (Exception e) { throw new ProcessException(e); } } }
cipher = cipherProvider.getCipher(encryptionMethod, new String(password.getPassword()), salt, keyLength, false); CipherUtility.processStreams(cipher, in, out); } catch (Exception e) { throw new ProcessException(e);
@Override public void process(final InputStream in, final OutputStream out) throws IOException { // Initialize cipher provider PBECipherProvider cipherProvider = (PBECipherProvider) CipherProviderFactory.getCipherProvider(kdf); // Generate salt byte[] salt; // NiFi legacy code determined the salt length based on the cipher block size if (cipherProvider instanceof org.apache.nifi.security.util.crypto.NiFiLegacyCipherProvider) { salt = ((org.apache.nifi.security.util.crypto.NiFiLegacyCipherProvider) cipherProvider).generateSalt(encryptionMethod); } else { salt = cipherProvider.generateSalt(); } // Write to output stream cipherProvider.writeSalt(salt, out); // Determine necessary key length int keyLength = CipherUtility.parseKeyLengthFromAlgorithm(encryptionMethod.getAlgorithm()); // Generate cipher try { Cipher cipher = cipherProvider.getCipher(encryptionMethod, new String(password.getPassword()), salt, keyLength, true); // Write IV if necessary if (cipherProvider instanceof RandomIVPBECipherProvider) { ((RandomIVPBECipherProvider) cipherProvider).writeIV(cipher.getIV(), out); } CipherUtility.processStreams(cipher, in, out); } catch (Exception e) { throw new ProcessException(e); } } }