> 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/get-locking-key.md).

# 6.4 Get Locking Key

Most developers do not need to use this function, and should instead rely on appropriate lock/unlock methods for encrypting and decrypting all data. This is meant only for highly advanced use-cases where the developer needs to use some custom encryption algorithm and/or explicitly add/validate signatures on some special piece of data or stream which can’t be easily passed to standard lock/unlock methods. In this case, the keys returned by this function should be used very carefully for a single object or stream, and then destroyed immediately after encryption/decryption or signature generation/verification is done.

The `getLockingKey` function returns locking key along with the keys for signature generation and signature verification for an encryption policy, key generation policy.&#x20;

The function takes the following parameters :

* **sessionId** : Unique SessionId which is received in the login/registration function response.
* **encryptionPolicy** : [BayunEncryptionPolicy](/bayuncoresdk-javascript-programming-guide/bayuncoresdk-operations.md#encryption-policy) determines the 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`.&#x20;

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

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

```javascript
bayunCore.getLockingKey(
    "<sessionId>",
    BayunCore.EncryptionPolicy.GROUP,
    BayunCore.KeyGenerationPolicy.STATIC,
    "<groupId>"
  )
  .then(result => {
    console.log("Response received for getLockingKey.");
    console.log(result);
  })
  .catch(error => {
    console.log("Error caught");
    console.log(error);
  });
```

{% endtab %}
{% endtabs %}

The `getLockingKey` function returns an object where the keys are `CryptoKey` objects.

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

```javascript
{
    key,  //Locking Key
    signatureKey, //Private Key to be used for signature generation
    signatureVerificationKey, //Public Key to be used for signature verification
};
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
To get the same keys as strings in PEM format, use the method`getLockingKeyForEncryptionPolicyAsString`.
{% endhint %}
