# Hash Creation in Postman

**URL:** <https://community.postman.com/t/hash-creation-in-postman/17503>\
**Category:** Help Hub\
**Created:** [November 8, 2020, 12:05pm UTC](https://community.postman.com/t/hash-creation-in-postman/17503 "2020-11-08T12:05:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [November 8, 2020, 12:05pm UTC](https://community.postman.com/t/hash-creation-in-postman/17503/1 "2020-11-08T12:05:45Z")

</div>

Hi Team,

we are using the marvel developer APIs for QA hiring purpose but we observed hash issues, who we will create the hash in the API.  
You can create account from “[https://developer.marvel.com/account](https://developer.marvel.com/account)” website if doesn’t have already.

End Point: [https://gateway.marvel.com:443/v1/public/characters](https://gateway.marvel.com:443/v1/public/characters)  
Error occurred and says

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/8/986a61dd474aa5e79dcddb5258ffaf223fb27945.png)

To remove error, we need to give the public key as a parameter as highlighted below

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/d/7/d7ae38d7cc816329663c1e7b72a678c6e1f9bbf0.png)

When I added public key as parameter, I got the error as “hash unavailable”  
Could you please suggest how we can create hash parameter

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/d/1/d1458eb23ac0a8aee238e3530a47708e4a1257f4.png)

I found something from google but not exact the same

- **hash** - a md5 digest of the ts parameter, your private key and your public key (e.g. md5(ts+privateKey+publicKey)  
CryptoJS.MD5(timestamp+privateKey+publicKey)

Could someone please let me know I can create hash from timestamp, private and public key.

---

<div class="post-metadata">

**Author:** ![yusuftaymann](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/yusuftaymann/32/6160_2.png) [@yusuftaymann](https://community.postman.com/u/yusuftaymann)\
**Post date:** [November 8, 2020, 5:44pm UTC](https://community.postman.com/t/hash-creation-in-postman/17503/2 "2020-11-08T17:44:40Z")

</div>

Hey @aakashjain8693,

Welcome to the community 👋

Actually, it asks you to send ts (timestamp) and apiKey and hash when sending requests. If the API key will be your public key hash, it should be timestamp + privateKey + publicKey as you said.

[https://www.md5hashgenerator.com/](https://www.md5hashgenerator.com/) you can generate a sample hash here.

You can easily access information from this document. [Authorizing and Signing Requests](https://developer.marvel.com/documentation/authorization)

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/1/a1d1e7a7a2c34a1cbf29652d4f5f278554326f66.png)

You can hire me. I’m just kidding 😅

---

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [November 9, 2020, 8:46am UTC](https://community.postman.com/t/hash-creation-in-postman/17503/3 "2020-11-09T08:46:45Z")

</div>

Thanks, Got the missing points.  
Definitely let me connect you for the hiring process 🙂

Just for the reference, I created pre-request Script too.

```auto
const public1=pm.environment.get("public");
const private1=pm.environment.get("private");
const time=pm.environment.get("ts");
hash= CryptoJS.MD5(time+private1+public1).toString();
pm.environment.set('hash', hash);
console.log(hash);  

```

Do you have any idea why we can not go ahead with timestamp value as “{{$timestamp}}” to get the system generated values?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 9, 2020, 9:21am UTC](https://community.postman.com/t/hash-creation-in-postman/17503/4 "2020-11-09T09:21:20Z")

</div>

> [@aakashjain8693](#):
>
> `const time=pm.environment.get("ts");`

This would need to be replaced with `const time=pm.environment.replaceIn("{{$timestamp}}");` if you wanted to use that dynamic variable in the request.

---

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [November 9, 2020, 9:57am UTC](https://community.postman.com/t/hash-creation-in-postman/17503/5 "2020-11-09T09:57:11Z")

</div>

Script as

```auto
const public1=pm.environment.get("public");
const private1=pm.environment.get("private");
const time=pm.environment.replaceIn("{{$timestamp}}");
hash= CryptoJS.MD5(time+private1+public1).toString();
pm.environment.set('hash', hash);
console.log(hash);

```

Nope, Error introduced as

```auto
{
    "code": "InvalidCredentials",
    "message": "That hash, timestamp and key combination is invalid."
}

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 9, 2020, 10:00am UTC](https://community.postman.com/t/hash-creation-in-postman/17503/6 "2020-11-09T10:00:48Z")

</div>

Without knowing what `ts` was in the environment variable and why you needed to change this to `{{$timestamp}}` - This code doesn’t really mean anything.

The code will create _something_ with a timestamp, using that dynamic variable.

```auto
const public1 = pm.environment.get("public"),
    private1 = pm.environment.get("private"),
    time = pm.environment.replaceIn("{{$timestamp}}"),
    hash = CryptoJS.MD5(time + private1 + public1).toString();
    
pm.environment.set('hash', hash);

console.log({time})
console.log({hash})

```

 ![Screenshot 2020-11-09 at 10.10.09](https://us1.discourse-cdn.com/getpostman/original/3X/e/c/ec22710e339afb255a9d9a0fd27020d6521bb4a6.png)

It feels like using something that you don’t know how to use, as a portal for hiring someone new seems strange.

---

<div class="post-metadata">

**Author:** ![aakashjain8693](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@aakashjain8693](https://community.postman.com/u/aakashjain8693)\
**Post date:** [November 9, 2020, 11:18am UTC](https://community.postman.com/t/hash-creation-in-postman/17503/7 "2020-11-09T11:18:57Z")

</div>

Thanks @danny-dainton.  
Yup, Strange but org. looking into different perspective.

Anyway thanks for the solution. I was just looking for different views on ts hard code value as “1” and timestamp system generated encrypted code.

---

<div class="post-metadata">

**Author:** ![lunar-module-candida](https://avatars.discourse-cdn.com/v4/letter/l/c37758/32.png) [@lunar-module-candida](https://community.postman.com/u/lunar-module-candida)\
**Post date:** [December 29, 2020, 6:51pm UTC](https://community.postman.com/t/hash-creation-in-postman/17503/8 "2020-12-29T18:51:53Z")

</div>

use [MD5 HASH Generator](https://codebeautify.org/md5-hash-generator) to generate sample hash for testing.

---

<div class="post-metadata">

**Author:** ![sahuvikramp](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/sahuvikramp/32/10828_2.png) [@sahuvikramp](https://community.postman.com/u/sahuvikramp)\
**Post date:** [March 1, 2022, 5:18pm UTC](https://community.postman.com/t/hash-creation-in-postman/17503/9 "2022-03-01T17:18:25Z")

</div>

Hash creation has been one of the interesting topic around, so we created a Postman’s public collection for encryption and decryption using Crypto JS.

[![Run in Postman](https://run.pstmn.io/button.svg)](https://god.gw.postman.com/run-collection/18070393-66f7caac-3005-44b2-8620-16dfb64a35f4?action=collection%2Ffork&collection-url=entityId%3D18070393-66f7caac-3005-44b2-8620-16dfb64a35f4%26entityType%3Dcollection%26workspaceId%3Daa5fb3b8-0090-4b5e-b3b4-fa5c1f2d080d)

Cheers 🎉

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [August 23, 2023, 3:40pm UTC](https://community.postman.com/t/hash-creation-in-postman/17503/10 "2023-08-23T15:40:24Z")

</div>

Closed on August 23, 2023, 3:40pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
