## Related terms

- data\-transformation
- workflow
- automation\-module

See the [glossary](/glossary.md) for definitions.

---

# Encrypt Data


The **Encrypt Data** transformation step lets you encrypt values in selected columns of a dataset. It enhances data security and confidentiality by encrypting sensitive information with AES-256 key using AES-GCM mode that is unreadable without the proper decryption key.  

To decrypt the data, you can use the [**Decrypt Data** step](/docs/automation/data-transformation-and-imports/transformations-and-data-operators/decrypt-data) or an external tool.

By using this transformation, you can safeguard your data and comply with privacy regulations while maintaining the integrity of your dataset.


## Requirements
---
- You must have a user role with the following permission: **Settings > Encryption keys > Read**. This permission lets you see the list of encryption keys in the **Encrypt Data** and **Decrypt Data** steps. 
- [Add an encryption key in Synerise](/docs/settings/data-exchange-encryption)
- Your decryption tool/program must support the Synerise encryption format: `base64encode([IV] + [Encrypted Text] + [Authentication Tag])`, where `IV` is the initialization vector used to initiate the encryption algorithm and `Encrypted Text` is the result of an AES-GCM algorithm with a 256-bit secret.



## Step configuration
---

<figure><img src="/api/docs/image/219f337699cf7b17198d03b7a7c7f148886e25a1/docs/automation/_gfx/dts-encrypt-data.png" class="medium" alt="Configuration of the Encrypt Data step"><figcaption>Configuration of the Encrypt Data step</figcaption></figure>

1. In the Data Transformation Studio, [add](/docs/automation/data-transformation-and-imports/creating-data-transformation#add-transformation-steps) the **Encrypt Data** step.
2. [Indicate the columns](#selecting-columns) whose values will be encrypted.
3. In the **Encrypt data using** section, click **Choose key** and select the key with which the data will be encrypted.
4. To add more rules, click **Add rule** and repeat steps 2-3.
5. To define what happens if rows contain errors, from the dropdown list next to **Add rule**, select one of the [error handling](#handle-errors) options.
6. Confirm the settings by clicking **Apply**.  
7. You can check the result in the **Output** tab.

### Selecting columns

In each rule of the step, you indicate the columns on which the operation is performed.

1. In the header of the rule, click **these** and select one of the options:
    - **these** - the operation is performed on the columns you indicate.
    - **all except these** - the operation is performed on all columns except the ones you indicate.  
2. From the first dropdown list in the rule, select how you want to indicate the columns:
    - **Columns** - from the **Select column** dropdown list, select one or more columns.
    - **Where name** - define a condition (a _dynamic condition_) that the column names must meet. Select a logical operator (**Ends with**, **Starts with**, **Contain**, **Not contain**, or **Regex**) and enter the value. For example, if you select **Starts with** and enter `pro`, the operation is performed on the columns whose names start with `pro`  
    Column names are case-sensitive, for example, `product` doesn't match `ProductCode`. A regular expression must match the entire column name, for example, `product.*` matches `productName`, but `product` doesn't. To ignore the letter case in a regular expression, add `(?i)` at the beginning, for example, `(?i)product.*`

You can't combine dynamic conditions with the **all except these** option.

Dynamic conditions are especially helpful when you use a JSON file as sample data. When a JSON file contains an object deeper than the root object, its items are transferred to the transformation as separate columns named `{object}.{parameter}`. You can't add those columns from the **Select column** list, but you can include them with a dynamic condition, for example, by including columns whose names contain the name of the object they were created from.

### Handle errors

You can define what happens with rows in which the step fails (for example, as a result of Jinja rendering). From the dropdown list next to **Add rule**, select one of the following options:
- **Skip row if error occurred** - It omits the row when an exception occurs.
- **Skip if result is null or empty string** - It omits rows with empty strings and `null` (which may be the result of rendering Jinja).
- **Stop further transformation** - The transformation stops at the row with an error. The data before the line that caused the error is transformed (and imported if the transformation is used in the Data Transformation Studio node).
- **Insert null if error occurred** - Wrong values are replaced with `null`. If you use such a transformation for the import of profiles, the existing value of an attribute is cleared and replaced with the `null` value.
- **Insert empty string if error occurred** - Wrong value is removed and the cell remains empty.

## Example of use
---

You can use the **Encrypt Data** step to encrypt a set of sensitive data. For example, you want to encrypt a column in a CSV file that contains email addresses of your customers. This example of use contains instructions how to create a transformation that encrypts a set of sensitive data. You can use this transformation in the ["Data Transformation Studio" node](/docs/automation/operation/data-transformation-node) in a workflow that sends the file to an external source. 

Before you proceed to creating a transformation that uses this step, ensure that you meet the [requirements](#requirements).


<details class="accordion"><summary>Sample data used in this example</summary><div class="accordion-content"><pre><code class="language-plaintext">email,newsletter agreement john.doe@example.com,yes jane.smith@example.com,no bob.johnson@example.com,yes sara.white@example.com,yes michael.brown@example.com,no</code></pre></div></details>


1. In the Data Transformation Studio, [add sample data](/docs/automation/data-transformation-and-imports/creating-data-transformation#add-sample-data) which imitates the structure of the data that will be transformed in the workflow.  
2. Click **Add step** and select **Encrypt Data**.  
3. From the **Select column** dropdown list, select the **email** column.
4. In the **Encrypt data using** section, click **Choose key** and select the Synerise encryption key which will be used to encrypt data in this column.  
5. Confirm the settings by clicking **Apply**.  
    **Result**: In the **Output** tab, the values in the **email** column are encrypted.

In the further steps, you can create a workflow that is triggered repeatedly, retrieves customers with email address assigned, encrypts email addresses with the transformation created in the previous steps, and sends the encrypted file with SFTP.  

<figure><img src="/api/docs/image/219f337699cf7b17198d03b7a7c7f148886e25a1/docs/automation/_gfx/encrypt-workflow.png" class="large" alt="Example workflow that uses a transformation"><figcaption>Example workflow that uses a transformation</figcaption></figure>


