DataPower

 View Only
Expand all | Collapse all

How to generate the session key using aes algorithm in gatewayscript

  • 1.  How to generate the session key using aes algorithm in gatewayscript

    Posted Thu January 20, 2022 10:56 PM
    Hi all,

    I am new to gateway script, I have created encryption using AES 256 GCM algorithm using Crypto module in Gateway script. My Requirement is I need to create dynamic session key for each request and I need to encrypt with that session key. In XSLT I can achieve using dp:generate-key() using AES algorithm but In Gatewayscript I am not sure how to generate session key specific to AES.

    It is working in shared secret key with alias name as 'name:sharedsecretkey',If I hardcoded the key with 256 bit also error coming as "key not found" and in the parameter I have used Buffer.from(key) in this its coming error as "key length shoud be 256 bit...Invalid length"

    I have tried the transform-xslt() function in Gatewayscript and from XSLT I got the sessionkey values but if I pass the session key parameter in the createcipheriv() method I am getting the error as "the  ******* key is not found".

    Can anyone share sample encryption with dynamic session key in Gatewayscript it will be helpful for me to understand.

    Thanks in advance

    Thanks
    Hari

    ------------------------------
    Hari Prasanth
    ------------------------------


  • 2.  RE: How to generate the session key using aes algorithm in gatewayscript

    Posted Fri January 21, 2022 09:33 AM
    Hi Hari
    are u using crypto module? U may try adding these lines in ur scrypt

    var crypto = require('crypto');
    var <session_key_name> = crypto.randomBytes(32);


    ------------------------------
    Nitish Sinha
    ------------------------------



  • 3.  RE: How to generate the session key using aes algorithm in gatewayscript

    Posted Mon January 24, 2022 12:37 AM
    Dear Nitish,

    Thanks for the reply,

    One more clarification, I need to append the session key in the XML request so that target system will decrypt based on session key.

    I cant append the bytes so I have converted in hex/base64 and then appended in xml request and sended to target system.

    Kindly confirm whether its correct or not.

    Thanks
    Hari

    ------------------------------
    Hari Prasanth
    ------------------------------