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.  How to decode base64 encoded string with gateway script in DataPower gateway.

    Posted Mon August 26, 2024 12:04 PM

    Hi, 

    I have a requirement to extract user id and password from X-Authorization header. 

    I am using gateway script to extract X-Authorization header value which is in base64 encoded format. 

    When i try to decode extracted header value i tried with below buffer function , I am getting request in buffer data format. Can you please help with the steps to extract result value in plain text. 

    var AuthHeader = new Buffer('Zm9vAGJhcg==','base64');

    Thanks.



    ------------------------------
    srikanth talluri
    ------------------------------


  • 2.  RE: How to decode base64 encoded string with gateway script in DataPower gateway.

    Posted Mon August 26, 2024 06:09 PM

    Hi Srikanth,
    To decode a base64 encoded string:

    let toDecode = 'dXNlcmlkOnBhc3N3b3Jk'; // base-64 encoded userid:password
    let decoded = Buffer.from(toDecode, 'base64').toString();

    Best Regards,

    Steve Linn



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------



  • 3.  RE: How to decode base64 encoded string with gateway script in DataPower gateway.

    Posted Mon August 26, 2024 06:39 PM

    Hi Steve,

    Thanks for your quick reply.

    Now I am able to decode string.

    Thank you.



    ------------------------------
    srikanth talluri
    ------------------------------



  • 4.  RE: How to decode base64 encoded string with gateway script in DataPower gateway.

    Posted Tue August 27, 2024 07:48 AM

    Be careful - this part is safe:
    ```
    let decoded = Buffer.from(toDecode, 'base64')
    ```

    ".toString()" will only work if the buffer contains "string" data.



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