Sha256 -toolbox hmac

Hello ,

I am trying to build a SMA256 signature using toolbox , I saw the following code posted by @miguel :

var crypto = require(‘crypto’)
, text = ‘I love cupcakes’
, key = ‘abcdeghi’
, hash;

var hash = crypto.createHmac(‘sha256’, key).update(text).digest(‘hex’);

var base64 = Buffer.from(hash).toString(‘base64’);

I have parameters to add , how do i add them in this code and where do i add my secret key please ? I tried to ask chat gpt and it gave me the following code:

const crypto = require(‘crypto’);

// Input data as an object
const inputData = {
vads_action_mode: “INTERACTIVE”,
vads_amount: “5124”,
vads_ctx_mode: “TEST”,
vads_currency: “953”,
vads_page_action: “PAYMENT”,
vads_payment_config: “SINGLE”,
vads_site_id: “12345678”,
vads_trans_date: “20170129130025”,
vads_trans_id: “123456”,
vads_version: “V2”
};

// Function to generate the SHA-256 Base64 key
function generateSHA256Base64Key(dataObject, secretKey) {
// Sort the keys alphabetically and concatenate “key=value” pairs
const sortedData = Object.keys(dataObject)
.sort() // Sort keys alphabetically
.map(key => ${key}=${dataObject[key]}) // Create “key=value” pairs
.join(“&”); // Join pairs with ‘&’

console.log('Concatenated string:', sortedData); // Debug: see the concatenated string

// Append the secret key at the end (if required by the algorithm)
const finalData = `${sortedData}&${secretKey}`;

// Create the SHA-256 hash and encode it in Base64
const hash = crypto.createHash('sha256').update(finalData).digest('base64');

return hash;

}

// Example secret key (replace with your actual secret key)
const secretKey = “your_secret_key”;

// Generate the key
const base64Key = generateSHA256Base64Key(inputData, secretKey);

console.log(‘Generated SHA-256 Base64 Key:’, base64Key);

However when i try to add the result to an item , nothing is happening… Can someone help me please?

Do i need to add the parameters here , in key and values?

I managed to get the right output as it is shown in the server log , however i can’t retrieved it in my database when I tried to update an element of my database , adding this text to it. Why bbubble does not see this as a text? The part i am looking for is this one : vSlCWjJwN8TpobRyuyKhwAlKEhlThtICZiI/rmpPK4U=

: START RequestId: 8ef77f40-bbe7-408a-9bf7-ff4368025253 Version: $LATEST 2024-11-21T11:23:17.858Z 8ef77f40-bbe7-408a-9bf7-ff4368025253 INFO vSlCWjJwN8TpobRyuyKhwAlKEhlThtICZiI/rmpPK4U= END RequestId: 8ef77f40-bbe7-408a-9bf7-ff4368025253 REPORT RequestId: 8ef77f40-bbe7-408a-9bf7-ff4368025253 Duration: 232.79 ms Billed Duration: 233 ms Memory Size: 128 MB Max Memory Used: 87 MB Init Duration: 381.09 ms