Search code examples
javascriptbase64obfuscationencode

Encoding / obfuscate a javascript object


I am considering giving users code to embed certain javascript elements from my website. They are all customised versions of a generic base configuration.

I have got the code working as I want, but within the code I will be giving to users to embed there is a javascript object. I was wondering if there is a nice way to encode the object so that the user can't too easily tamper with it and will make it look somewhat more professional. I considered using base64 but thought it would be best to ask if anyone has any better ideas before I go down that route.


Solution

  • You can compress your code, shrink variable names and use a Base64 encoding. For example, javascriptcompressor.com does all at once for you (it actually uses Base62 encoding), but it is really not that hard to undo all of it.

    Base64 decoding is as easy as encoding. Same goes for the compression (removal of line breaks, etc.). The only thing that complicates understanding the code a little is shrinking the variables, as it cannot be automatically undone.

    Still, everybody that knows JavaScript will be able to "tamper" with your code. As for looking professional, I do not think that you gain anything in that sense, but that's just me...