# Configuring PublicKey in Sunbird-RC

### Step 1

Generate public key

```bash
# Note: Execute the commands one by one.
openssl genrsa -out key.pem; cat key.pem;

openssl rsa -in key.pem -pubout -out pubkey.pem;
```

### Step 2

Open `pubkey.pem` in an text editor and copy the contents of it. And convert multilines into single line by replacing new line to `\r\n`

```
# Example for Copied from pubkey.pem
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCqwefadcfafdCAQEA4EQdY0cnP8DmBgigxIYP
0cJi7hQVQHDKUw8m+7dY82XQypA123123123123qsddjRkl+lWLdWT2ubekyylDT
7p0cbVKSU7aEYm/Ng7z3OSZKr124oirfqwefdaffw23QjhY5ft1wZ6pYyfWgIIr2
TI6uDUvEFspmj0t5HcKuIB0762Zol43sevcjkpX1znejIJAATpkvaleGFpHNgqwj
bYwzrDpxaDm6Mjgr3FuEjFvr8a94qfqdasdcwef13efEipwn2iTZmiIa4/FVJDhK
uBkQF7bbXvEFobI+vfgjiILhLCLdasdavrqcqs3cHUTl/d+XYsPPUDLchAC+BfyT
AwI3dasB
-----END PUBLIC KEY-----


# Example for converted public key
-----BEGIN PUBLIC KEY-----\r\nMIIBIjANBgkqhkiG9w0BAQEFAAOCqwefadcfafdCAQEA4EQdY0cnP8DmBgigxIYP\r\n0cJi7hQVQHDKUw8m+7dY82XQypA123123123123qsddjRkl+lWLdWT2ubekyylDT\r\n7p0cbVKSU7aEYm/Ng7z3OSZKr124oirfqwefdaffw23QjhY5ft1wZ6pYyfWgIIr2\r\nTI6uDUvEFspmj0t5HcKuIB0762Zol43sevcjkpX1znejIJAATpkvaleGFpHNgqwj\r\nbYwzrDpxaDm6Mjgr3FuEjFvr8a94qfqdasdcwef13efEipwn2iTZmiIa4/FVJDhK\r\nuBkQF7bbXvEFobI+vfgjiILhLCLdasdavrqcqs3cHUTl/d+XYsPPUDLchAC+BfyT\r\nAwI3dasB\r\n-----END PUBLIC KEY-----
```

### Step 3

Pass the converted publickey in the payload of below curl command and make the API call.

```sh
curl --location --request POST '{{rc_host}}/registry-service/api/v1/PublicKey' \
--header 'Content-Type: application/json' \
--data-raw '{"value":"-----BEGIN PUBLIC KEY-----\r\nMIIBIjANBgkqhkiG9w0BAQEFAAOCqwefadcfafdCAQEA4EQdY0cnP8DmBgigxIYP\r\n0cJi7hQVQHDKUw8m+7dY82XQypA123123123123qsddjRkl+lWLdWT2ubekyylDT\r\n7p0cbVKSU7aEYm/Ng7z3OSZKr124oirfqwefdaffw23QjhY5ft1wZ6pYyfWgIIr2\r\nTI6uDUvEFspmj0t5HcKuIB0762Zol43sevcjkpX1znejIJAATpkvaleGFpHNgqwj\r\nbYwzrDpxaDm6Mjgr3FuEjFvr8a94qfqdasdcwef13efEipwn2iTZmiIa4/FVJDhK\r\nuBkQF7bbXvEFobI+vfgjiILhLCLdasdavrqcqs3cHUTl/d+XYsPPUDLchAC+BfyT\r\nAwI3dasB\r\n-----END PUBLIC KEY-----"}'
```

Note: Value for `rc_host` can be found from certificate generater flink job's config map. Config key is `service.rc.basePath`

### Step 4

Make the search API call to verify if the publickey is available.

```sh
curl --location --request POST '{{rc_host}}/registry-service/api/v1/PublicKey/search' \
--header 'Content-Type: application/json' \
--data-raw '{
    "filters": {
    }
}'
```


---

# 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://lern.sunbird.org/use/developer-guide/lms-service/certificate-registry-and-credentialing/configuring-publickey-in-sunbird-rc.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.
