tags:

views:

178

answers:

6

Possible Duplicate:
How can I obfuscate JavaScript?

Hello!

Is it possible to hide JS code? How? I read somewhere a technique like: take JS to external file, and use js-encrypt.

I know that is impossible to hide from all eyes, but...

Thank you.

+5  A: 

It is not possible to hide Javascript from the user, since their browser needs to download it to execute it. The only other option is obfuscation.

Dead account
I agree; security through obscurity isn't very good security at all...
CrazyJugglerDrummer
A: 

The simple answer is no - since the browser needs to understand the javascript, then the user will be able to understand the javascript...

rATRIJS
+4  A: 

See this question, which includes some good conversation about this.

Tim S. Van Haren
+1 for finding dupe. I've voted to close as dupe.
Dead account
+1  A: 

You can run your private JavaScript server side e.g. using ASP JScript.NET

<% WebService Language="JScript" Class="MyClass" %>

You can put the hidden functionality on the server and call it via AJAX in the non hidden part of the code on the client.

you can also use

<script runat="server">

or if you're not using a Microsoft platform you might consider Mozilla Rhino

PeanutPower
Seems like a flippant response but it's the only solution to hiding code.
nicerobot
A: 

As you can take someone else's code and try to encrypt it, same goes for others who can take your code. The only solution that i think is to obfuscate your javascript code so that it becomes little difficult for others to grasp but there again there decryptors available so no real solution as of what i know has come about so far.

I am sure these links are going to help you much though:

http://www.portaldepot.net/articles/HideCodePg2.html

http://www.15seconds.com/howto/pg000916.htm

Sarfraz
portaldepot: i mentioned the solution what they try to sell. But i dont wanna sell a solution, which is not 100%.
Holian
A: 

While there isn't a 100% foolproof method of doing so, there are ways of hiding the JS away from the client.

This article may be what you are looking for: http://bytes.com/topic/javascript/insights/749685-hide-javascript-code-client

Urda
Don't waste your time. That article is inaccurate. There's no way to do it. If the browser needs to execute the javascript, it has it cached and the cache is viewable. In firefox, simply use firebug. It's very easy to see code in Javascript. Functions evaluate to the function body. Essentially, println(foo) will print the body of function foo. Since the page contains the functions because they are executing, the function bodies are available for anyone. Solution: never put code on the client if it needs to be hidden.
nicerobot