> For the complete documentation index, see [llms.txt](https://docs.bayunsystems.com/bayuncoresdk-python/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bayunsystems.com/bayuncoresdk-python/bayuncoresdk-operations/lock-unlock-binary-data.md).

# 5.3 Lock/Unlock Binary Data

## &#x35;**.3.1 Lock Binary Data**

The `lockData` function of `BayunCore` class locks binary data with default encryption-policy dictated by server settings.

The function takes the following parameters :

* **sessionId** : Unique SessionId which is received in the authenticate function response.
* **data** : Data to be locked.
  * dataType : `bytes`
* **data\_len** : Length of the data to be locked.

{% tabs %}
{% tab title="Python" %}

```python
data = b'Hello World!'
data_len = len(data)
lockDataOutput = bayunCore.lockData("<sessionId>", data, data_len)
locked_data = lockDataOutput.data
locked_binary_data = locked_data.tobytes()
locked_binary_data_len = lockDataOutput.data_len
```

{% endtab %}
{% endtabs %}

## **5.3.2 Lock Binary Data with encryption-policy**

The `lockData` function with encryption-policy as an optional parameter locks data with the encryption key dictated by the policy. The function takes the following parameters :

* **sessionId** : Unique SessionId which is received in the authenticate function response.
* **data** : Data to be locked.
  * dataType : `bytes`
* **data\_len** : Length of the data to be locked.
* **encryptionPolicy** : [BayunEncryptionPolicy](https://docs.bayunsystems.com/bayuncoresdk-python/bayuncoresdk-operations#encryption-policy) determines the key for locking.
* **keyGenerationPolicy** : [BayunKeyGenerationPolicy](https://docs.bayunsystems.com/bayuncoresdk-python/bayuncoresdk-operations#key-generation-policy) determines the policy to generate the data encryption key.
* **groupId** : GroupId is required if encryptionPolicy is `BayunEncryptionPolicyGroup`.

{% hint style="info" %}
Note : If encryption-policy is other than `BayunEncryptionPolicyGroup` then groupId should be empty string.
{% endhint %}

{% tabs %}
{% tab title="Python" %}

```python
from BayunCore import BayunEncryptionPolicy
from BayunCore import BayunKeyGenerationPolicy

data = b'Hello World!'
data_len = len(data)
encryptionPolicy = BayunEncryptionPolicy.Company
keyGenerationPolicy = BayunKeyGenerationPolicy.Static
lockDataOutput = bayunCore.lockData("<sessionId>", data, data_len, encryptionPolicy, keyGenerationPolicy, "<groupId>")
locked_data = lockDataOutput.data
locked_binary_data = locked_data.tobytes()
locked_binary_data_len = lockDataOutput.data_len
```

{% endtab %}
{% endtabs %}

## **5.3.3 Unlock Binary 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 authenticate function response.
* **data** : Data to be unlocked.
  * dataType : `bytes`
* **data\_len** : Length of data to be unlocked.

{% tabs %}
{% tab title="Python" %}

```python
unlockData_output =  bayunCore.unlockData(sessionId, <data>, <data_len>)
unlocked_data = unlockData_output.data
unlocked_binary_data = unlocked_data.tobytes()
unlocked_binary_data_len = unlockData_output.data_len
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.bayunsystems.com/bayuncoresdk-python/bayuncoresdk-operations/lock-unlock-binary-data.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
