X10nD
X10nD

Reputation: 22030

Encrypt jQuery javascript file

I have a whole range of jQuery code, how do I stop users from seeing the actual code, or how can I encrypt the .js file.

Please suggest opensource

Thanks Jean

[edit] I don't want users to know how I have coded or copy my code

[edit] Once I use the base62 encode, can it be reverse engineered?

Upvotes: 4

Views: 10240

Answers (7)

Kothar
Kothar

Reputation: 6629

This is the first thing I found, but it looks like it might do the job:

http://www.vincentcheung.ca/jsencryption/instructions.html

As others have mentioned though, the browser has to be be able to decrypt the code, so the user would also be able to (although it may be some work to do so).

You should look at obfuscation too, which will make the code much harder to reverse engineer.

http://www.javascriptobfuscator.com/Default.aspx

Upvotes: 0

Will Earp
Will Earp

Reputation: 312

There is not really much point in encrypting your js file, everyone knows you can view the source code of anyone's website. I believe there are encryptors out there for javascript, but users will have to download the decryptor module to decrypt it. Also since the browser does need to interpret the code, it would probably not be that hard to circumvent.

You could obfuscate the code, but I would do this using a minification technique, and more for performance reasons rather that hiding the code, some obfuscators are more intrusive than others, but again, the code could be re-formatted, albiet the original variable names will not be recoverable.

Upvotes: 1

Gerard Banasig
Gerard Banasig

Reputation: 1713

You can use google closure compiler

http://code.google.com/closure/

The Closure Compiler compiles JavaScript into compact code, it obfuscates the code, it can still be read but it will be hard to trace and will take time

Upvotes: 2

Jarrett Meyer
Jarrett Meyer

Reputation: 19573

Check out packer by Dean Edwards. It has the ability to encode your JS. You have to let your JS be world readable, otherwise a browser couldn't download it.

Upvotes: 5

mck89
mck89

Reputation: 19231

Try to pack the code with the packer: http://dean.edwards.name/packer/

This is not like code encryption, but it obfuscate the code.

Upvotes: 1

AndiDog
AndiDog

Reputation: 70128

You just can't encrypt JavaScript that runs on the client machine. Browsers need the unencrypted code in order to execute it!

Upvotes: 0

Pascal MARTIN
Pascal MARTIN

Reputation: 400972

You cannot prevent your users from being able to see the source code of a Javascript file : it's executed by the user's browser, which means it must be readable on the client side.

The "best" you can do it minify/obfuscate it ; see for instance the YUI Compressor, which exists to minify JS files (so they are smaller, and can be transferred faster), but also has some obfuscating functionnalities.

If will make you Javascript code harder to read/understand -- but someone really motivated will still be able to read it ; well, it will take some time and a bit of work, but it'll still be possible.

Upvotes: 4

Related Questions