# 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 of `BayunCore` class returns locking key along with the keys for signature generation and signature verification for an encryption policy.&#x20;

The function takes the following parameters :

* **encryptionPolicy** : [BayunEncryptionPolicy](https://bayun.gitbook.io/bayuncoresdk-android/5.-bayuncoresdk-methods#encryption-policy) determines the key to be used to generate the lockingKey.
* **keyGenerationPolicy** : [BayunKeyGenerationPolicy](https://bayun.gitbook.io/bayuncoresdk-android/5.-bayuncoresdk-methods#key-generation-policy) determine the policy to be used to generate the lockingKey.
* **groupId** : GroupId is required if encryptionPolicy is `BayunEncryptionPolicyGroup`. If encryption-policy is other than `BayunEncryptionPolicyGroup` then groupId should be empty string.

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

```java
import com.bayun_module.LockingKeys

int encryptionPolicy =encryptionPolicy;         //bayunCore.ENCRYPTION_POLICY_DEFAULT
int keyGenerationPolicy =keyGenerationPolicy;    //bayunCore.KEY_GENERATION_POLICY_STATIC
String groupId = "<groupId>";

LockingKeys lockingKeys = bayunCore.getLockingKey(encryptionPolicy, keyGenerationPolicy, groupId);


```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
 import com.bayun_module.LockingKeys
 
 val encryptionPolicy:Int =encryptionPolicy         //bayunCore.ENCRYPTION_POLICY_DEFAULT
 val keyGenerationPolicy:Int =keyGenerationPolicy    //bayunCore.KEY_GENERATION_POLICY_STATIC
 val groupId = "groupId"
 
 var lockingKeys :LockingKeys= bayunCore.getLockingKey(encryptionPolicy, keyGenerationPolicy, groupId)
```

{% endtab %}
{% endtabs %}

The `getLockingKey` function returns a struct `LockingKeys`.

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

```java
public class LockingKeys {
    public String key;//Locking Key
    public String signatureKey; //Private Key to be used for signature generation
    public String signatureVerificationKey; //Private Key to be used for signature generation
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
class LockingKeys {
            var key : String? = null //Locking Key
            var signatureKey : String? = null  //Private Key to be used for signature generation
            var signatureVerificationKey : String? = null  //Private Key to be used for signature generation
        }
```

{% 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-android/5.-bayuncoresdk-methods/6.4-get-locking-key.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.
