# 5.2 Lock/Unlock Text

### 5.2.1 Lock Text

The `lockText` function of `BayunCore` class locks text 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.
* **plainText** : Text to be locked.
  * dataType : `std::string`

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

```cpp
#include "BayunCore.h"

std::string cipherText = bayunCore->lockText("<sessionId>", "<plainText>");
```

{% endtab %}
{% endtabs %}

### 5.2.2 Lock Text with Encryption Policy, Key Generation Policy

The `lockText` function with encryption policy, key generation policy as parameters locks text 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.
* **plainText** : Text to be locked.
  * dataType : `std::string`
* **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;

std::string lockedText =  bayunCore->lockText("<sessionId>", "<plainText>", encryptionPolicy, keyGenerationPolicy, "<groupId>");

```

{% endtab %}
{% endtabs %}

### 5.2.3 Unlock Text

The `unlockText` function of `BayunCore` class unlocks a locked text. The function takes the following parameters :

* **sessionId** : Unique SessionId which is received in the registration/login function response.
* **lockedText** : Text to be unlocked.
  * dataType : `std::string`

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

```cpp
#include "BayunCore.h"

std::string plainText = bayunCore->unlockText("<sessionId>", "<lockedText>");
```

{% endtab %}
{% endtabs %}


---

# 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://bayun.gitbook.io/bayuncoresdk-cpp/bayuncoresdk-operations/lock-unlock-text.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.
