# Data Protection

{% hint style="info" %}

### **This module is available as part of Ecotone Enterprise.**

{% endhint %}

Ecotone will help you to encrypt your messeges (Events or Commands) right before they leave and decrypt them when they are received by your domain. In other words, message will remain readable within the application but once they leave the system, secured key is required for reading.

## Installation

```bash
composer require ecotone/data-protection
```

## Configuration

Required `DataProtectionConfiguration` will let you to provide set of encryption keys used within the system.

```php
use Ecotone\DataProtection\Configuration\DataProtectionConfiguration;
use Ecotone\DataProtection\Encryption\Key;

class DataProtection
{
    #[ServiceContext]
    public function dataProtectionConfiguration(): DataProtectionConfiguration
    {
        return DataProtectionConfiguration::create(name: 'primary-key', key: Key::loadFromAsciiSafeString(...)) // first key will be set as default
            ->withKey(name: 'secondary-key', key: Key::loadFromAsciiSafeString(...))
            ->withKey(name: 'default-key', key: Key::loadFromAsciiSafeString(...), asDefault: true) // overwrite default key passing `asDefault: true`
        ;
    }
}
```

{% hint style="warning" %}
Ecotone does not manage your encryption keys. They are used based on given configuration.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ecotone.tech/modules/data-protection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
