Encrypt and decrypt personal data with Spark Databricks.We create a table that will include personal information. However, we want to hide personal id...

Hubert-Dudek
Databricks MVP

Encrypt and decrypt personal data with Spark Databricks.

image.pngWe create a table that will include personal information. However, we want to hide personal identifiers so no one can see them.

image.pngWe set a key. A key need to have 16, 24, or 32 bytes. 1 byte = 1 char.We use a widget for that. It is only for development purposes. In production, we should store that key in Key Vault.

image.pngWe are inserting data into the table. Phone field we are encrypting using the aes_encrypt function. Since Databricks runtime 10.3, we can use aes_encrypt and aes_decrypt functions.

image.pngNow we can preview the data. Data without encrypting is unreadable.

image.pngWe need to use the aes_decrypt function with our key when we want to read it.

image👉 Please watch also my video about aes_encrypt and aes_decrypt:

➡️ https://www.youtube.com/watch?v=OGLf_PiFMks

image.pngLink to GitHub with the above notebook: https://github.com/hubert-dudek/databricks-hubert/blob/main/linkedin/decrypt%20encrypt/decrypt%20enc...


My blog: https://databrickster.medium.com/