Base64 Decode source under transformation script to GUID

Tagged: 

This topic has 3 replies, 3 voices, and was last updated 4 months ago by Jatinder Singh (AcceptingNewProjects).

  • Author
    Posts
  • #27979
     rohit.mahajan
    Participant

    Hello,

    I am trying to decode base64 string into GUID. Is there any library I can use to convert it into guid ?

    For example:
    Base64 String = “qcx4JyAvkUi2HolTPX+q5A==” convert it into GUID = “2778cca9-2f20-4891-b61e-89533d7faae4” under IDM transforamtion script.

    Regards
    Rohit Mahajan

    #27980
     Chris Drake
    Participant

    Rohit,

    You can call the org.forgerock.util.encode.Base64.decode() method directly within you transform script in order to decode the Base64 encoded String. Note that Base64.decode() returns byte[] and therefore if you require a String you will need to do something along the lines of the following:

    String.fromCharCode.apply(String, org.forgerock.util.encode.Base64.decode('Q2xlYXIgVGV4dCBTdHJpbmc='));

    Sample using Curl:

    curl --request POST 'http://localhost:8080/openidm/script?_action=eval' \
    --header 'X-OpenIDM-Username: openidm-admin' \
    --header 'X-OpenIDM-Password: openidm-admin' \
    --header 'Content-Type: application/json' \
    --data-raw '{"type" : "javascript", "source" : "String.fromCharCode.apply(String, org.forgerock.util.encode.Base64.decode('\''Q2xlYXIgVGV4dCBTdHJpbmc='\''));"}'

    Regards,
    Chris

    #27981
     rohit.mahajan
    Participant

    Thanks for your response.

    I am getting below error on both local instance as well as on the Test system

    {"code":500,"reason":"Internal Server Error","message":"TypeError: second argument to Function.prototype.apply must be an array"}

    Also I am able to decode the base64 string using below

    	var base64 = Packages.org.forgerock.util.encode.Base64url
    	b64tO = new Packages.java.lang.String(base64.decode(source));
    	logger.info("Decoded: {}", b64tO);

    Now I want to convert it into GUID.
    Regards
    Rohit Mahajan

    #27985

    GUID is an arbitrary global unique identifier. You can encode/decode a GUID. But i am not sure what you mean by – “convert it into GUID”? GUID is usually a generated value.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

©2020 ForgeRock - we provide an identity and access platform to secure every online relationship for the enterprise market, educational sector and even entire countries. Click to view our privacy policy and terms of use.

Log in with your credentials

Forgot your details?