---
title: Calculate signature
slug: ki/calculate-signature
description: Learn how to generate secret keys and calculate signatures using HMAC_SHA256 with this comprehensive document. Find out how non-printable characters can be included in derived keys and explore the varying parameter orders in HMAC library functions for dif
docTags: 
createdAt: 2023-06-30T03:29:06.176Z
---



- The pseudo code is as follows:

:::CodeblockTabs
Bash

```none
SecretKey = "Gu5t9xGARNpq86cd98joQYCN3*******"
SecretDate = HMAC_SHA256("K1" + SecretKey, Date)
SecretService = HMAC_SHA256(SecretDate, Service)
SecretSigning = HMAC_SHA256(SecretService, "k1_request")
```
:::

The derived keys, such as SecretDate, SecretService and SecretSigning, are binary data and may contain non printable characters.

Please note that the order of parameters in HMAC library functions may be different for different programming languages, and the actual situation shall prevail. Here, the pseudo code key parameter key comes before and the message parameter data comes after. Usually, the standard library function will provide the return value in binary format, and it may also provide the return value in hexadecimal format which is friendly to printing. Here, the binary format is used.

| **Name**  | **Description**                                                                          |
| --------- | ---------------------------------------------------------------------------------------- |
| SecretKey | SecretKey: `Gu5t9xGARNpq86cd98joQYCN3*******`                                            |
| Date      | The Date field information in the Credential. The value of this example is `2019-02-25`. |
| Service   | Service field information in Credential. The value of this example is `cbms`.            |

- Calculate signature, the pseudo code is as follows:

:::CodeblockTabs
Bash

```none
Signature = HexEncode(HMAC_SHA256(SecretSigning, StringToSign))
```
:::

The calculation results of this example are as follows: `2230eefd229f582d8b1b891af7107b91597240707d778ab3738f756258d7652c`
