Search code examples
pythonapache-nifipycrypto

PyCryptodome alternative for jython


I am trying to incorporate a simple encrypting processor for Apache Nifi. I am using the Script Processor module to include a Python script that does the function on encrypting and decrypting with AES. I am having trouble loading the module PyCryptodome (I also tried pycrypto), that was offering me the functionality. I have read that this module cannot be loaded as it is not pure python, which is, aparently, not supported by Nifi.

Any suggestion of what can I use as an alternative to this module?


Solution

  • It's not that NiFi doesn't support native Python modules per se, rather it is the Jython engine that we use in NiFi (as NiFi is a pure Java implementation) that does not support it. If you have a Python interpreter on the node(s) running NiFi, you could use ExecuteStreamCommand to shell out to Python using your script (with native imports), you'd get the contents of the flow file as stdin and you'd write your encrypt/decrypt logic to output to stdout, which would become the contents of the outgoing flow file.

    I'm looking into a Py4J processor so we can get around Jython's limitation on native modules, but you'd still have to Bring Your Own Python (BYOP). For now, as long as you don't want to do anything more complex than taking in flow file content and writing out flow file content, ExecuteStreamCommand should do the trick.