hide your JavaScript

If there is a reason why you don’t want humans to read your JavaScript code, you can use the packer from
http://dean.edwards.name/packer/ to obfuscated it (online).

The packer compress the code to one line, deletes all comments and has the option to encode it with Base62. You can put the generated code in your code, it should work with any browser.
You must correctly terminate all JavaScript statements with semi-colons.

Here an example script and the output from the packer:

var a, b;

a = “hello “;
b = “world!”;

function send_msg(a, b) {
// alert a and b
alert(a +b);
}

send_msg(a, b);

after packing

var a,b;a=”hello “;b=”world!”;function send_msg(a,b){alert(a+b)}send_msg(a,b);

after packing and Base62 encoding

eval(function(p,a,c,k,e,r){e=String;if(!”.replace(/^/,String)){while(c–)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return’\w+’};c=1};while(c–)if(k[c])p=p.replace(new RegExp(‘\b’+e(c)+’\b’,’g’),k[c]);return p}(‘6 0,1;0=”5 “;1=”3!”;4 2(0,1){7(0+1)}2(0,1);’,8,8,’a|b|send_msg|world|function|hello|var|alert’.split(‘|’),0,{}))
Advertisements

2 comments so far

  1. Schwarzkophf on

    Nice info …
    Thanks for share …

  2. ali on

    hi,

    re: hide js

    nice article…

    how about PHP ? – what’s the best way of protecting PHP source code in you opinion/experience?

    thanks.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: