> For the complete documentation index, see [llms.txt](https://bayun.gitbook.io/bayuncoresdk-cpp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bayun.gitbook.io/bayuncoresdk-cpp/bayuncoresdk-operations/lock-unlock-binarydata.md).

# 5.3 Lock/Unlock Binary Data

### 5.3.1 Lock Data

The `lockData` function of `BayunCore` class locks binary data with default [BayunEncryptionPolicy](https://bayun.gitbook.io/bayuncoresdk-cpp/bayuncoresdk-operations#encryption-policy) and  [BayunKeyGenerationPolicy](https://bayun.gitbook.io/bayuncoresdk-cpp/bayuncoresdk-operations#key-generation-policy) dictated by server settings.

The function takes the following parameters :

* **sessionId** : Unique SessionId which is received in the registration/login function response.
* **data** : Data to be locked.
  * dataType : `unsigned char*`
* **data\_len** : Length of the data to be locked.
  * dataType : `size_t`

{% tabs %}
{% tab title="C++" %}

```cpp
#include "BayunCore.h"

ShLockedData lockedData = bayunCore->lockData("<sessionId>", "<data>", <data_len>);
```

{% endtab %}
{% endtabs %}

### 5.3.2 Lock Data with Encryption Policy, Key Generation Policy

The `lockData` function with encryption policy, key generation policy as parameters locks data with the encryption key dictated by the policy. The function takes the following parameters :

* **sessionId** : Unique SessionId which is received in the registration/login function response.
* **data** : Data to be locked.
  * dataType : `unsigned char*`
* **data\_len** : Length of the data to be locked.
  * dataType : `size_t`   &#x20;
* **encryptionPolicy** : [BayunEncryptionPolicy](/bayuncoresdk-cpp/bayuncoresdk-operations.md#encryption-policy) determines the key to be used to generate the lockingKey.
* **keyGenerationPolicy** : [BayunKeyGenerationPolicy](/bayuncoresdk-cpp/bayuncoresdk-operations.md#key-generation-policy) determines the policy to generate the data encryption key.
* **groupId** : GroupId is required if encryptionPolicy is BayunEncryptionPolicyGroup.

{% hint style="info" %}
If encryptionPolicy is other than `BayunEncryptionPolicyGroup` then groupId should be nil.
{% endhint %}

{% tabs %}
{% tab title="C++" %}

```cpp
#include "BayunCore.h"

Bayun::BayunEncryptionPolicy encryptionPolicy = Bayun::BayunEncryptionPolicy::Company;
Bayun::BayunKeyGenerationPolicy keyGenerationPolicy = Bayun::BayunKeyGenerationPolicy::Envelop;
ShLockedData lockedData = bayunCore->lockData("<sessionId>", "<data>", <data_len>, encryptionPolicy, keyGenerationPolicy, "<groupId>");
```

{% endtab %}
{% endtabs %}

### 5.3.3 Unlock Data

The `unlockData` function of `BayunCore` class unlocks a locked binary data. The function takes the following parameters :

* **sessionId** : Unique SessionId which is received in the registration/login function response.
* **data** : Data to be unlocked.
  * dataType : `unsigned char*`
* **data\_len** : Length of data to be unlocked.
  * dataType : `size_t`

{% tabs %}
{% tab title="C++" %}

```cpp
#include "BayunCore.h"

ShUnlockedData unlockedData =  bayunCore->unlockData(sessionId, "<data>", <data_len>);
```

{% endtab %}
{% endtabs %}
