<?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>topic Re: How to Apply Encryption Function to a Specific Column in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-apply-encryption-function-to-a-specific-column/m-p/106699#M42556</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/118852"&gt;@weilin0323&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have you tried the built-in function? Refer to below encryption code snippet.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;create table if not exists catalog.schema.testencryption(
  id int,
  name string,
  tss string
);

insert into catalog.schema.testencryption
values (1,'sam','123-123-123'),
(2,'john','456-456-456'),
(3,'pat','789-789-789');

SELECT
  id,
  name,
  base64(aes_encrypt(tss, 'sample_key_16by.', 'GCM')) AS encrypted_tss
FROM
  catalog.schema.testencryption;&lt;/LI-CODE&gt;&lt;P&gt;without encryption:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MadhuB_1-1737568383906.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/14287i08CD81347E4F846F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MadhuB_1-1737568383906.png" alt="MadhuB_1-1737568383906.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;with encryption:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MadhuB_0-1737568365714.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/14286i38A4FA84FFBA8150/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MadhuB_0-1737568365714.png" alt="MadhuB_0-1737568365714.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please let me know if there is anything else. Otherwise, please mark it as a solution.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jan 2025 17:59:35 GMT</pubDate>
    <dc:creator>MadhuB</dc:creator>
    <dc:date>2025-01-22T17:59:35Z</dc:date>
    <item>
      <title>How to Apply Encryption Function to a Specific Column</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-apply-encryption-function-to-a-specific-column/m-p/106577#M42524</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I would like to apply a function to encrypt a specific column. The UDF is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;DROP FUNCTION IF EXISTS EncryptColumn;
CREATE FUNCTION EncryptColumn (key_name STRING, encryptcolumn STRING) 
RETURN base64(aes_encrypt(encryptcolumn, key_name, 'GCM', 'DEFAULT', 'Some AAD'))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;The parameter 'key_name' is the encryption key, and 'encryptcolumn' is the column to be encrypted.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;I tried using the following:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;ALTER TABLE table_name 
ALTER COLUMN column_name 
SET MASK EncryptColumn(key_name, column_name)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;However, this approach seems to accept only one parameter.&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="weilin0323_0-1737526512566.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/14255iB878F132B57BA6BF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="weilin0323_0-1737526512566.png" alt="weilin0323_0-1737526512566.png" /&gt;&lt;/span&gt;&lt;BR /&gt;Therefore, I would like to ask if there is any way to apply a function to encrypt a column in the Databricks UC architecture?&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Thank you for your response!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 06:18:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-apply-encryption-function-to-a-specific-column/m-p/106577#M42524</guid>
      <dc:creator>weilin0323</dc:creator>
      <dc:date>2025-01-22T06:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to Apply Encryption Function to a Specific Column</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-apply-encryption-function-to-a-specific-column/m-p/106699#M42556</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/118852"&gt;@weilin0323&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have you tried the built-in function? Refer to below encryption code snippet.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;create table if not exists catalog.schema.testencryption(
  id int,
  name string,
  tss string
);

insert into catalog.schema.testencryption
values (1,'sam','123-123-123'),
(2,'john','456-456-456'),
(3,'pat','789-789-789');

SELECT
  id,
  name,
  base64(aes_encrypt(tss, 'sample_key_16by.', 'GCM')) AS encrypted_tss
FROM
  catalog.schema.testencryption;&lt;/LI-CODE&gt;&lt;P&gt;without encryption:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MadhuB_1-1737568383906.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/14287i08CD81347E4F846F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MadhuB_1-1737568383906.png" alt="MadhuB_1-1737568383906.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;with encryption:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MadhuB_0-1737568365714.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/14286i38A4FA84FFBA8150/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MadhuB_0-1737568365714.png" alt="MadhuB_0-1737568365714.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please let me know if there is anything else. Otherwise, please mark it as a solution.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 17:59:35 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-apply-encryption-function-to-a-specific-column/m-p/106699#M42556</guid>
      <dc:creator>MadhuB</dc:creator>
      <dc:date>2025-01-22T17:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to Apply Encryption Function to a Specific Column</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-apply-encryption-function-to-a-specific-column/m-p/106737#M42568</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/131860"&gt;@MadhuB&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;The method you provided is feasible, and I later finded other ways to apply UDF:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;UPDATE table_name 
SET column_name = EncryptColumn(key_name, column_name)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 00:46:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-apply-encryption-function-to-a-specific-column/m-p/106737#M42568</guid>
      <dc:creator>weilin0323</dc:creator>
      <dc:date>2025-01-23T00:46:24Z</dc:date>
    </item>
  </channel>
</rss>

