DataPower

DataPower

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
  • 1.  Symmetric Encryption in Gateway script

    Posted Tue January 30, 2024 03:34 PM

    I am trying to use symmetric encryption using a shared secret key. Whenever I am saving the hex string directly in stylesheet parameter, it is working.

    However, when I am storing the string in a .key file and creating shared secret key object, I am receiving error saying that key length is not matching with algorithm.

    I am using createcipherIv function available in crypto module of Gateway script. Please let me know how can we store the Hex string in key file and refer the same shared secret key in GW script.



    ------------------------------
    R K
    ------------------------------


  • 2.  RE: Symmetric Encryption in Gateway script

    Posted Wed January 31, 2024 07:48 AM
    Edited by Hermann Stamm-Wilbrandt Wed January 31, 2024 07:48 AM

    You need to store binary data in the key file.
    The data from buffer or buffers structure:
    https://www.ibm.com/docs/en/datapower-gateway/10.0.1?topic=gatewayscript-key-object-usage


    If you store hex string, they key file has twice the size needed.



    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support, IBM DataPower Gateways
    IBM
    Boeblingen Germany
    ------------------------------



  • 3.  RE: Symmetric Encryption in Gateway script

    Posted Wed January 31, 2024 11:08 AM

    Dear Hermann,

    Is there any way to save the hex or base 64 string and save the file in .key to refer as Sharedsecret key. ?



    ------------------------------
    R K
    ------------------------------



  • 4.  RE: Symmetric Encryption in Gateway script

    Posted Wed January 31, 2024 11:48 AM
    Edited by Hermann Stamm-Wilbrandt Wed January 31, 2024 11:50 AM

    Create buffer with binary data.

    From base64 encoded string:
     new Buffer(b64str, "base64");

    From hex encoded string:
     new Buffer(hexstr, "hex");

    Then use fs module to write the buffer in local/store/temporary into file:
    https://www.ibm.com/docs/en/datapower-gateway/10.0.1?topic=apis-fs-module

    Finally use file manager to copy file from there to sharedcert.



    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support, IBM DataPower Gateways
    IBM
    Boeblingen Germany
    ------------------------------