thunderclient / thunder-client-support

Thunder Client is a lightweight Rest API Client Extension for VS Code.
https://www.thunderclient.com
Other
3.62k stars 128 forks source link

HMAC calculation is not same as POSTMAN #1538

Closed Jaivijay029 closed 4 months ago

Jaivijay029 commented 5 months ago

Question: HMAC calculation is not same as POSTMAN for below script

POSTMAN: var ClientRequestId = 1234567; var time = 1715167893828; var requestBody = request.data; var rawSignature = key + ClientRequestId + time + requestBody;

var computedHash = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, secret.toString()); computedHash.update(rawSignature); computedHash = computedHash.finalize(); var computedHmac = CryptoJS.enc.Base64.stringify(computedHash);

ThunderClient: var ClientRequestId = 1234567; var time = 1715167893828; var requestBody = tc.request.body; var rawSignature = key + ClientRequestId + time + requestBody;

var crypto = require('crypto-js') var computedHash = crypto.algo.HMAC.create(crypto.algo.SHA256, secret.toString()); computedHash.update(rawSignature); computedHash = computedHash.finalize(); var computedHmac = crypto.enc.Base64.stringify(computedHash);

tc.setVar("key", key, "request"); tc.setVar("time", time, "request"); tc.setVar("signature", computedHmac, "request"); tc.setVar("ClientRequestId", ClientRequestId, "request");

Are you using the free version/paid version/trial: Free version

rangav commented 4 months ago

CryptoJS is deprecated in postman, try require("crypto-js") and let me know.

Screenshot 2024-05-11 at 17 48 57
Jaivijay029 commented 4 months ago

@rangav Issue is not with Postman.. In Postman it is working as expected. In Thunder client we are not getting expected result for HMAC calculation.