# OpenAPI Authentication issues - signature calculation

**URL:** <https://community.postman.com/t/openapi-authentication-issues-signature-calculation/49299>\
**Category:** Help Hub\
**Created:** [July 6, 2023, 7:55pm UTC](https://community.postman.com/t/openapi-authentication-issues-signature-calculation/49299 "2023-07-06T19:55:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vsapountzis-pageauth](https://avatars.discourse-cdn.com/v4/letter/v/6f9a4e/32.png) [@vsapountzis-pageauth](https://community.postman.com/u/vsapountzis-pageauth)\
**Post date:** [July 6, 2023, 7:55pm UTC](https://community.postman.com/t/openapi-authentication-issues-signature-calculation/49299/1 "2023-07-06T19:55:59Z")

</div>

I am working on a project for an integration with [HikCentral Professional OpenAPI](https://tpp.hikvision.com/tpp/HCPIntegration).

I want to send a couple of requests to the API but I am unable to properly authenticate.

I have created partner appKey and appSecret but based on the documentation I have to also calculate X-CA-Signature with HmacSHA-256 and base64.

I am trying to do this through postman at the moment but I haven’t had much luck with the pre-request scripts.

I used the following to generate the signature in JS inside postman in order to set it as a variable:

```auto
var signature = CryptoJS.HmacSHA256("secret-key").toString();
pm.environment.set("appSignature", "signature");

```

The above doesn’t work, (probably because it is missing the base64 encoding?) although CryptoJS is a postman built-in library.

I also tried to generate the signature with Python on a separate script:

```auto
import hashlib
import hmac
import base64

secret = "secret-key"

hashed = hmac.new(secret.encode(), b"", hashlib.sha256)
digest = hashed.digest()
base64_encoded = base64.b64encode(digest).decode()

print(base64_encoded)

```

I have set the above encoded signature manually as a value in the headers of postman but I get timeouts in the response.

Any help would be appreciated.

Thanks!

 ![Screenshot 2023-07-06 at 10.23.37 PM](https://us1.discourse-cdn.com/getpostman/original/3X/d/9/d9866e99cf9e401415996c9ddbcb9ea38b7efc90.png)

---

<div class="post-metadata">

**Author:** ![vsapountzis-pageauth](https://avatars.discourse-cdn.com/v4/letter/v/6f9a4e/32.png) [@vsapountzis-pageauth](https://community.postman.com/u/vsapountzis-pageauth)\
**Post date:** [July 11, 2023, 3:57pm UTC](https://community.postman.com/t/openapi-authentication-issues-signature-calculation/49299/2 "2023-07-11T15:57:39Z")

</div>

Any ideas? Anyone?

I would appreciate any help.

Thanks!

---

<div class="post-metadata">

**Author:** ![ThatooTT](https://avatars.discourse-cdn.com/v4/letter/t/91b2a8/32.png) [@ThatooTT](https://community.postman.com/u/ThatooTT)\
**Post date:** [October 7, 2024, 4:35am UTC](https://community.postman.com/t/openapi-authentication-issues-signature-calculation/49299/3 "2024-10-07T04:35:08Z")

</div>

Hi, also working on HikVision API, I can’t seem to get the signature thing correct. I wanted to comment on your stackoverflow solution so that I can have a look since you said they sent you a collection on how to generate and authenticate.

---

<div class="post-metadata">

**Author:** ![vsapountzis-pageauth](https://avatars.discourse-cdn.com/v4/letter/v/6f9a4e/32.png) [@vsapountzis-pageauth](https://community.postman.com/u/vsapountzis-pageauth)\
**Post date:** [October 7, 2024, 9:06am UTC](https://community.postman.com/t/openapi-authentication-issues-signature-calculation/49299/4 "2024-10-07T09:06:34Z")

</div>

Hi,

Yes, I was actually able to resolve it by using instructions Hik has shared with me, including the signature calculation as well as the postman collection.

Please, send me a pm to share a dropbox link with you, as I am unable to upload PDFs and Zip files here and in the meantime check this here as well:

[https://www.postman.com/elbert1990/hki-hik-api/collection/ntf0ruw/hcp-openapi](https://www.postman.com/elbert1990/hki-hik-api/collection/ntf0ruw/hcp-openapi)

Might prove helpful.
