Original Message:
Sent: Wed April 05, 2023 09:34 AM
From: Jyoti Yadav
Subject: AES256 GCM Encryption/Decryption Implementation using Datapower
Hello All,
While decryption, we are getting output while using decipher.update(resp, 'base64') method, but while using decipher.final() method getting length error.
Please help how to implement decyption using AES-256/GCM in Gatewayscript.
Thanks and Regards,
Jyoti Yadav
------------------------------
Jyoti Yadav
Original Message:
Sent: Tue April 04, 2023 09:24 AM
From: Jyoti Yadav
Subject: AES256 GCM Encryption/Decryption Implementation using Datapower
Hello Joseph,
Thank you for support.
Can we implement AES256-GCM algorithm on Datapower using KEY-IV pair? if yes, then please help how to do it.
As well, We have tried with Gatewayscript using "crypto" module.We are able to encrypt payload, but while decrypt it getting error.
Please find below code and correct me if its wrong.
Please find below Enrycpt/DEcrypt code with OP
Encrypt:
apim.output('application/json');
var crypto = require('crypto');
var SymKey ='NTBERTg1NzQzQ0YwMzEzRUI4MUI5NzFCQTM1NkYwODQ=';//base64Encoded Key
var iv1='4932AF1AC8C2F21F';
var buff = new Buffer(SymKey, 'base64');
var buff1=new Buffer(iv1,'base64');
var cipher = crypto.createCipheriv('A256GCM', buff,buff1);
var pay_load = '{"abc":"ad"}';
var resp = JSON.stringify(pay_load);
var b2=cipher.update(resp, 'utf8').final('base64');
//var encipherData = cipher.final('base64');
//var Jdata=encipherData;
session.output.write({"EncryptedPayload":b2});
OP:
{
"EncryptedPayload": "SEGBiol1LIqbOl7ejrQo36hM"
}
Decrypt:
var EncryptedResponse=apim.getvariable('request.body.EncryptedPayload');
apim.output('application/json');
var crypto = require('crypto');
var SymKey ='NTBERTg1NzQzQ0YwMzEzRUI4MUI5NzFCQTM1NkYwODQ=';
var iv1='4932AF1AC8C2F21F'
var buf = new Buffer(SymKey,'base64');
var buff = new Buffer(iv1,'base64');
var decipher = crypto.createDecipheriv('A256GCM',buf,buff);
var resp = JSON.stringify(EncryptedResponse);
var b2=decipher.update(resp, 'base64').final('utf8');
//decipher.update(resp, 'base64');
//var originalPlainText1 = decipher.final('utf8');
session.output.write(b2);
OP:
{
"httpCode": "500",
"httpMessage": "Internal Server Error",
"moreInformation": "Cannot read property 'length' of undefined"
}
------------------------------
Jyoti Yadav
Original Message:
Sent: Wed March 29, 2023 02:17 PM
From: Joseph Morgan
Subject: AES256 GCM Encryption/Decryption Implementation using Datapower
Jyoti,
The answer is yes, but this question is overly broad because there are so many ways.
If using the Encrypt/Decrypt actions on a processing rule, then go to the "Advanced" tab, and select "AES256 GCM" next to "Permitted Bulk Encryption Algorithm".
If using the xslt encrypt-data/decrypt-data extensions, use the 'http://www.w3.org/2009/xmlenc11#aes256-gcm" algorithm.
If using gatewayscript, use the "cipher" and "decipher" API. Use the "createCipheriv(...) and provide "A256GCM" as the algorithm.
------------------------------
Joseph Morgan
Original Message:
Sent: Wed March 29, 2023 02:09 AM
From: Jyoti Yadav
Subject: AES256 GCM Encryption/Decryption Implementation using Datapower
Hello Team,
Can we perform AES256 GCM Encryption/Decryption implementtaion on Datapower. if yes, please help how to do it.
------------------------------
Jyoti Yadav
------------------------------