How to Apply Encryption Function to a Specific Column

weilin0323
New Contributor III

Hello!

I would like to apply a function to encrypt a specific column. The UDF is as follows:

 

DROP FUNCTION IF EXISTS EncryptColumn;
CREATE FUNCTION EncryptColumn (key_name STRING, encryptcolumn STRING) 
RETURN base64(aes_encrypt(encryptcolumn, key_name, 'GCM', 'DEFAULT', 'Some AAD'))

 

 

The parameter 'key_name' is the encryption key, and 'encryptcolumn' is the column to be encrypted.
I tried using the following:

 

ALTER TABLE table_name 
ALTER COLUMN column_name 
SET MASK EncryptColumn(key_name, column_name)

 

 

However, this approach seems to accept only one parameter.
weilin0323_0-1737526512566.png
Therefore, I would like to ask if there is any way to apply a function to encrypt a column in the Databricks UC architecture?

Thank you for your response!