Hi Romil,
We have used below code, calculation of checksum for json request body using HmacSHA256 algorithm but getting "
invalid type 'undefined (undefined)' detected on method invocation. Method name: createHmac; Parameter index: 0; Expected type: string". So can you guide us what we are doing wroung exactly in code?
var crypto = require('crypto')
function checksumGenerate(str, algorithm, encoding,key) {
var key ="kpidfrtivrns5ZIvZdGOUirctckmjM";
return crypto
.createHmac(algorithm,key)
.update(str, 'utf8')
.digest(encoding || 'hex')
}
checksumGenerate('application/json')
var store = checksumGenerate('application/json', 'sha1');
//var str = {"CHECKSUM":store};
session.output.write(store);
apim.output('*/*');
------------------------------
Prashant Patel
------------------------------
Original Message:
Sent: Tue November 09, 2021 08:53 AM
From: Romil Garg
Subject: CHECKSUM
You will have to replace 'Alice' with your shared secret key object name
------------------------------
Romil Garg
Original Message:
Sent: Tue November 09, 2021 08:45 AM
From: Prashant Patel
Subject: CHECKSUM
Hi Romil,
We have used below code for HMAC but getting Named shared secret key 'Alice' not found
var crypto = require('crypto');
var key = "Alice";
var hmac = crypto.createHmac('hmac-sha256', key);
var input = "This is plaintext to hash";
var result = hmac.update(input).digest('base64');
session.output.write(result);
------------------------------
Prashant Patel
Original Message:
Sent: Tue November 09, 2021 07:55 AM
From: Romil Garg
Subject: CHECKSUM
Hi @prashant - You can create an HMAC using crypto.createHmac() module.
You can find an example and additional details on the module here:
https://www.ibm.com/docs/en/datapower-gateways/10.0.1?topic=apis-crypto-module#crypto.createHmac
------------------------------
Romil Garg
Original Message:
Sent: Tue November 09, 2021 04:36 AM
From: Prashant Patel
Subject: CHECKSUM
Hi Romil,
We want to use key which is given by client & use HmacSHA256 Algorithm for calculate checksum so can you guide us how we can implement checksum code?
------------------------------
Prashant Patel
Original Message:
Sent: Wed November 03, 2021 08:13 AM
From: Romil Garg
Subject: CHECKSUM
For checksum generation, you can make use of crypto module in GatewayScript. Here is an example -
var crypto = require('crypto')
function checksumGenerate(str, algorithm, encoding) {
return crypto
.createHash(algorithm || 'md5')
.update(str, 'utf8')
.digest(encoding || 'hex')
}
checksumGenerate('Your Text')
checksumGenerate('Your Text', 'sha1')
You can find more details on the modules and supported algorithms here:
https://www.ibm.com/docs/en/datapower-gateways/10.0.1?topic=apis-crypto-module
------------------------------
Romil Garg
Original Message:
Sent: Tue November 02, 2021 04:30 AM
From: Akshay Sawant
Subject: CHECKSUM
Hello Everyone,
We want to implement Checksum & GCM encryption using gateway script so can you guide us how we can implement this?
------------------------------
Akshay Sawant
------------------------------