Problem with encoded/encrypted strings

0 favourites
  • 4 posts
From the Asset Store
This collection of music is the beautiful performance of rather small strings ensemble (8 first violins, 6 second violin
  • I'm using encryption in my game to communicate with a server. The response I get back is a base64 encoded string that looks like this:

    To clarify, that's the type of value that comes back in AJAX.LastData 
    So then whenever I try to use this in ExecJS in this form:  
    Browser.ExecJS("window.var =" & AJAX.LastData & ";")
    I get the following error
    Uncaught SyntaxError: Unexpected token ILLEGAL
    It's likely that this is due to invisible zero-width space chars that may find themselves in the string, I'm not sure, I don't know how to save AJAX.LastData to a textfile to check.
    However, if I make a textbox and set its text to AJAX.LastData, then load its text in javascript, it works.  The textbox probably removes the bad characters (though a text label does not).  
    Is it possible to get C2 to remove these characters with a system expression? (trim does not work).  I tried looking with RegExp to find them but it's poorly documented so I was not sure how.  Something like trim() that removes all whitespace everywhere would probably work.
  • Browser.ExecJS("window.var =" & AJAX.LastData & ";")

    are you refering to a variable named "var" ? if so, if I am not mistaken, that is not allowed, and probably considered illegal in javascript

    Perhaps change it to:

    Browser.ExecJS("window.MyvariableName =" & AJAX.LastData & ";")

  • You need to add quotes in the expression around the encoded string, otherwise js thinks it's just a long variable name.

    Try this. Notice the added single quotes.

    Browser.ExecJS("window.var ='" & AJAX.LastData & "';")

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • lennaert R0J0hound

    Sorry I didn't copy/paste the actual code because I changed it to the working Textbox version I mentioned, so I introduced some red herrings on the board that are not part of the actual code.

    First, the variable is not called var, that was just a dummy name, it's called window.unencryptedresponse.

    Second, there are in fact quotes around the C2 data structure (either the ajax or textbox etc), here's the actual call.

    Browser.ExecJS("window.unencryptedresponse=encrypt ('mykeystring', atob('" & AJAX.LastData & "'), 0, 0,0, 1);  ")[/code:23l4u1k7]
    encrypt is the enryption function and its various parameters, atob and btoa are functions that convert from base64 and back.
    This is another call that fails for the same reason:
    [code:23l4u1k7]Browser.ExecJS("window.encryptedresponse='" & AJAX.LastData & "';") [/code:23l4u1k7]
    All of these actually work when using Textbox.Text instead of AJAX.LastData, (but not when using TextLabel.Text).  So that makes me fairly convinced that it must be some illegal characters in there that Textbox does not support and removes, and that error message is known to come up in chrome in those zero-width-space situations.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)