<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question How to encrypt a column using nifi in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/How-to-encrypt-a-column-using-nifi/m-p/335993#M232093</link>
    <description>&lt;P&gt;&lt;SPAN&gt;For security reasons I need to encrypt a column before putting the data in the repository. How can I do this using python or some processor. I tried to use the cryptography library but without success. If you can guide me which is the best way I would be very grateful.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Feb 2022 15:44:30 GMT</pubDate>
    <dc:creator>faabiianooc</dc:creator>
    <dc:date>2022-02-10T15:44:30Z</dc:date>
    <item>
      <title>How to encrypt a column using nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-encrypt-a-column-using-nifi/m-p/335993#M232093</link>
      <description>&lt;P&gt;&lt;SPAN&gt;For security reasons I need to encrypt a column before putting the data in the repository. How can I do this using python or some processor. I tried to use the cryptography library but without success. If you can guide me which is the best way I would be very grateful.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 15:44:30 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-encrypt-a-column-using-nifi/m-p/335993#M232093</guid>
      <dc:creator>faabiianooc</dc:creator>
      <dc:date>2022-02-10T15:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to encrypt a column using nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-encrypt-a-column-using-nifi/m-p/336023#M232103</link>
      <description>&lt;P&gt;Which repository are you referring to? An internal NiFi repository or the location your flow is writing data to?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use the EncryptContent processor to encrypt the whole content of the flowfile, but there isn't an easy way to a single field of a record. To do this you will have to use something like the ScriptedTransformRecord and provide a script that encrypts parts of your data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example of using&amp;nbsp;ScriptedTransformRecord with a Groovy script to encrypt the field "name":&lt;/P&gt;&lt;PRE&gt;import javax.crypto.Cipher&lt;BR /&gt;import javax.crypto.SecretKey&lt;BR /&gt;import javax.crypto.SecretKeyFactory&lt;BR /&gt;import javax.crypto.spec.IvParameterSpec&lt;BR /&gt;import javax.crypto.spec.PBEKeySpec&lt;BR /&gt;import javax.crypto.spec.SecretKeySpec&lt;BR /&gt;import java.security.Key&lt;BR /&gt;import java.security.spec.KeySpec&lt;BR /&gt;&lt;BR /&gt;String encryptionKey = "#{encryption.key}"&lt;BR /&gt;Key aesKey = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES")&lt;BR /&gt;Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding")&lt;BR /&gt;cipher.init(Cipher.ENCRYPT_MODE, aesKey)&lt;BR /&gt;record.setValue("name", cipher.doFinal(record.getValue("name").getBytes("UTF-8")).encodeBase64())&lt;BR /&gt;record&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;To decrypt it you could use:&lt;/P&gt;&lt;PRE&gt;import javax.crypto.Cipher&lt;BR /&gt;import javax.crypto.SecretKey&lt;BR /&gt;import javax.crypto.SecretKeyFactory&lt;BR /&gt;import javax.crypto.spec.IvParameterSpec&lt;BR /&gt;import javax.crypto.spec.PBEKeySpec&lt;BR /&gt;import javax.crypto.spec.SecretKeySpec&lt;BR /&gt;import java.security.Key&lt;BR /&gt;import java.security.spec.KeySpec&lt;BR /&gt;import java.util.Base64&lt;BR /&gt;&lt;BR /&gt;String encryptionKey = "#{encryption.key}"&lt;BR /&gt;Key aesKey = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES")&lt;BR /&gt;Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding")&lt;BR /&gt;cipher.init(Cipher.DECRYPT_MODE, aesKey)&lt;BR /&gt;record.setValue("name", cipher.doFinal(Base64.getDecoder().decode(record.getValue("name"))))&lt;BR /&gt;record&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The encrypt key is specified through a NiFi parameter called &lt;FONT face="courier new,courier,monospace"&gt;encryption.key&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;André&lt;/P&gt;</description>
      <pubDate>Fri, 11 Feb 2022 00:32:20 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-encrypt-a-column-using-nifi/m-p/336023#M232103</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-02-11T00:32:20Z</dc:date>
    </item>
  </channel>
</rss>

