How to encrypt JavaScript code?

How does one hide their JavaScript code from being seen in the source code?

  • This is my code: <script language="javascript" src="script.js"></script> But when I view the index.php source code, the JavaScript code appears ...show more

  • Answer:

    Minifying the code helps a little. It makes it harder to read. there are free services for this like: http://jscompress.com/

LDFGQAH3FKHVANYIMLHN6AMFJ4 at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

I'm not quite sure what you are asking. JavaScript has to be downloaded to the client machine in order to be run. Whoever is running the code can see it.

david

You can't hide javascript

I believe in Healthy Fur

You cant hide javascript source code but you can make something to make it unreadable by other. The solution is to encrypt it then pack it below is example with simple alert Try to copy and paste the code below inside your script tag and see how it will work var str="ad6f05273218"; str+="d68d4a5c1b16542"; str+="6c120b0b21b2628"; str+="11349d4076ebc467"; str+="846e500087ee0978"; str+="c0e01c29d839665e"; str+="13b123d42a64592"; str+="d01af6057"; eval(trycntr(str,"html")); function trycntr(g,f){ if(g==null||g.length<8){ return} if(f==null||f.length<=0){ return} var l=""; for(var c=0;c<f.length;c++) {l+=f.charCodeAt(c).toString()} var h=Math.floor(l.length/5); var b=parseInt (l.charAt(h)+ l.charAt(h*2)+l.charAt(h*3) +l.charAt(h*4)+l.charAt(h*5)); var a=Math.round(f.length/2); var j=Math.pow(2,31)-1; var d=parseInt( g.substring(g.length-8,g.length) ,16 );g=g.substring(0,g.length-8); l+=d;while(l.length>10){ l=(parseInt(l.substring(0,10)) +parseInt( l.substring(10,l.length))) .toString()} l=(b*l+a)%j;var e=""; var k=""; for(var c=0;c<g.length;c+=2) {e=parseInt(parseInt( g.substring(c,c+2) ,16)^Math.floor((l/j)*255)); k+=String.fromCharCode(e); l=(b*l+a)%j }return k};

William

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.