> For the complete documentation index, see [llms.txt](https://bayun.gitbook.io/bayuncoresdk-javascript-programming-guide/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-javascript-programming-guide/bayuncoresdk-operations/lock-unlock-text.md).

# 6.1 Lock/Unlock Text

### 6.1.1 Lock Text

The `lockText` function with encryption policy, key generation policy as parameters locks the plain text. The function takes the following parameters :

* **sessionId** : Unique SessionId which is received in the login/registration function response.
* **plainText** : Text to be locked.
* **encryptionPolicy** : [BayunEncryptionPolicy](/bayuncoresdk-javascript-programming-guide/bayuncoresdk-operations.md#encryption-policy) determines the base key to be used to generate the lockingKey.
* **keyGenerationPolicy** : [BayunKeyGenerationPolicy](/bayuncoresdk-javascript-programming-guide/bayuncoresdk-operations.md#key-generation-policy) determines the policy to generate the lockingKey.
* **groupId** : GroupId is required if encryptionPolicy is `GROUP.`

{% hint style="info" %}
If encryptionPolicy is other than `GROUP`  or `GROUP_ASYMMETRIC` then groupId should be an empty string.
{% endhint %}

{% hint style="info" %}
encryptionPolicy and keyGenerationPolicy can be passed as null for simplicity, bayun sdk will automatically take default settings of your org.
{% endhint %}

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

```javascript
const encryptionPolicy = BayunCore.EncryptionPolicy.GROUP;
const keyGenerationPolicy = BayunCore.KeyGenerationPolicy.ENVELOPE;

var lockedText = await bayunCore.lockText({
  sessionId: "<sessionId>",
  text: "<plainText>",
  encryptionPolicy: encryptionPolicy, // can be passed null
  keyGenerationPolicy: keyGenerationPolicy, // cab be passed null
  groupId: "<groupId>",
});
```

{% endtab %}
{% endtabs %}

### 6.1.2 Unlock Text

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

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

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

```javascript
var unlockedText = await bayunCore.unlockText({
  sessionId: "<sessionId>",
  lockedText: "<lockedText>",
});
```

{% endtab %}
{% endtabs %}
