how to encrypt javascript source code?

Javascript source code is clear text, which can be seen easily by right-clicking the web page and clicking the “view source code” menu item. To protect your javascript source code from being theft, you can encrypt it. The encrypted source code is syntax error-free but hard to be read by human. The javascript encryption method is:

1. use hard-to-read strings for variable names and function names including function parameters like:

function _0x7638x9(_0x882134)
{
    var _0x8732ex9=_0x882134;
}

2. rewrite constant strings with their hex representation, e.g. instead of  writing “ABCD”, we write it as “\x41\x42\x43\x44″.

3. hide system defined property names and method names : put system defined property names and method names in an array, and call them like:

_0x1234=["length","replace"];
var _0x5678="hello";
_0x5678[_0x1234[0]];
_0x5678[_0x1234[1]]("hi");

In the above example, we call the “length()” function of the variable. It is equal to:

var a="hello";
a.length;
a.replace("hi");

Note that the property and method of an object can not only be invoked by . (as we usually do) but also be invoked by []. Of course, you can further encode the strings “length” and “hello”,”hi” with their hex representations, to make the code even harder to understand.

4. put constant strings in an array(better also in encoded form) and refer to them using array elements.

With the above tricks applied, your javascript code will be difficult to be decoded, thus safer.

Comments are closed, but trackbacks and pingbacks are open.