API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

GCM Encryption/Decryption Implementation using Crypto Modules

  • 1.  GCM Encryption/Decryption Implementation using Crypto Modules

    Posted Fri March 24, 2023 01:39 AM

    Hello Team,

    How to perform AES256-GCM Encryption/Decryption logic using "crypto" module on API Connect. We have used below code (crypto module) to encrypt/decrypt text, able to encrypt text but while decrypt getting "Cannot read property 'length' of undefined" error. Please help how to implement it.

    As well can we perform AES256-GCM on Datapower. if yes, then please suggest how to do it? Please find below API connect and DataPower version.

    Version:

    API Connect: v10.0.1.5

    Datapower:10.0.1.5

    Code:

    Encryption:

    apim.output('application/json');

    var crypto = require('crypto');

    var SymKey ='Q1F1WUN4SVZOeVRPdDQ4NzA4NFVQQk14aFMwWHhSRTQ=';

    var iv1='dzZ0bXZLelVqNlJn';

    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);

    cipher. update(resp, 'utf8');

    var encipherData = cipher.final('base64');

    var Jdata=encipherData;

    session.output.write({"EncryptedPayload":Jdata});

    OP:

    {

        "EncryptedPayload": "VEEwUlk4c0xIVEtHY1BUOHFiOUI4M0V6"

    }

    Decrypt:

    var EncryptedResponse=apim.getvariable('request.body.EncryptedPayload');

    apim.output('application/json');

    var crypto = require('crypto');

    var SymKey ='Q1F1WUN4SVZOeVRPdDQ4NzA4NFVQQk14aFMwWHhSRTQ=';

    var iv1='dzZ0bXZLelVqNlJn';

    var buf = new Buffer(SymKey, 'base64');

    var buff = new Buffer(iv1, 'base64');

    var decipher = crypto.createDecipheriv('A256GCM',buf,buff);

    decipher. update(EncryptedResponse, 'base64');

    var originalPlainText1 = decipher.final('utf8');

    session.output.write(originalPlainText1);



    ------------------------------
    Jyoti Yadav
    ------------------------------


  • 2.  RE: GCM Encryption/Decryption Implementation using Crypto Modules

    Posted Mon April 17, 2023 02:22 AM

    Hello Team,

    Can we implement AES256- GCM ENcryption/Decryption on "IBM API Connect v5 " using "Crypto" Modules ? 

    Thanks 





    ------------------------------
    Jyoti Yadav
    ------------------------------