JongSnowflake's Forum Posts

  • 2 posts
  • I founded a code to convert base64 like this

    function base64url(source) {
     // Encode in classical base64
     var encodedSource = CryptoJS.enc.Base64.stringify(source);
     
     // Remove padding equal characters
     encodedSource = encodedSource.replace(/=+$/, '');
     
     // Replace characters according to base64url specifications
     encodedSource = encodedSource.replace(/\+/g, '-');
     encodedSource = encodedSource.replace(/\//g, '_');
     
     return encodedSource;
    }
    
    var stringifiedHeader = CryptoJS.enc.Utf8.parse(JSON.stringify(header));
    var encodedHeader = base64url(stringifiedHeader);
    document.getElementById("header").innerText = encodedHeader;
    
    var stringifiedData = CryptoJS.enc.Utf8.parse(JSON.stringify(data));
    var encodedData = base64url(stringifiedData);
    document.getElementById("payload").innerText = encodedData;
    
    var signature = encodedHeader + "." + encodedData;
    signature = CryptoJS.HmacSHA256(signature, secret);
    signature = base64url(signature);
    
    document.getElementById("signature").innerText = signature;
    

    But I don't know how to integrate to C3.

    And I'm finding the other way to convert base64 by using function like btoa()

    It seems difference output that using code from above to use in JWT.io

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi, I am new to C3 and either to Javascript coding but I am finding a way to use CryptoJS in C3 on anyway to convert my score and user id as Json Web Token and send them to my server API to check Authorization.

    I tried many way to find how to import a module or libraries to C3 Scripting but it doesn't work.

    Or, is there a better way to use CryptoJS to convert base64 string?

    Thanks

  • 2 posts