# 6.1 Lock/Unlock Text

### 6.1.1 Lock Text

The `lockText` function locks text with default [BayunEncryptionPolicy](https://bayun.gitbook.io/bayuncoresdk-javascript-programming-guide/bayuncoresdk-operations/..#encryption-policy) and [BayunKeyGenerationPolicy](https://bayun.gitbook.io/bayuncoresdk-javascript-programming-guide/bayuncoresdk-operations/..#key-generation-policy) dictated by company settings.

The function takes the following parameters :

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

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

```javascript
var lockedText = await bayunCore.lockText("<sessionId>", "<plainText>");
```

{% endtab %}
{% endtabs %}

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

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](https://bayun.gitbook.io/bayuncoresdk-javascript-programming-guide/bayuncoresdk-operations/..#encryption-policy) determines the key to be used to generate the lockingKey.
* **keyGenerationPolicy** : [BayunKeyGenerationPolicy](https://bayun.gitbook.io/bayuncoresdk-javascript-programming-guide/bayuncoresdk-operations/..#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` then groupId should be an empty string.
{% endhint %}

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

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

var lockedText = await bayunCore.lockText("<sessionId>", "<plainText>", 
                                 encryptionPolicy, keyGenerationPolicy, "<groupId>");
```

{% endtab %}
{% endtabs %}

### 6.1.3 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>", "<lockedText>");
```

{% endtab %}
{% endtabs %}
