pinkyponky

How to Encrypt JavaScript Code?

Recommended Posts

Hello Masters, I am a JavaScript toddler and I have created the Tic Tac Toe game using Plain JavaScript. 

Now how can I encrypt or protect my code so that no one could copy or steal it?

Note: I am not asking this question to save my Tic Tac Toe game but in future IF I make good games :)

Thank you.

Share this post


Link to post
Share on other sites

In short you can't. You can obfuscate, which might solve your problem, but you can't actually encrypt.

You could compile to ASM or WASM (I'm assuming you can go JS->WASM, I've only ever done C->WASM), this isn't encrypted either.

The web must remain transparent or bad things™ will happen (very bad things). So ask yourself if there are better ways of 'protecting' your game. The web is currently transparent, so even if your code is obfuscated junk it must be transmitted and that can be hijacked/stolen even without copy-pasting from your browser.

Encryption alone doesn't stop anything being stolen in any language anyway, if it runs it can be moved and run again. Think of other ways to protect your game, the absolute best is to continually improve your game so that players want to keep playing and keep playing the latest of your game.

Share this post


Link to post
Share on other sites

The majority of game developers have great technical skills. Most can copy your game without looking at the source, because they know how to do it.

Use your time to have great ideas and be the first to release them.

However, you should bundle and minimize your js files for size download reasons.

Share this post


Link to post
Share on other sites

You can't prevent people from stealing client-side code, the best you can do is make the code harder to read and understand. JavaScript minification with variable renaming will do that a bit, or you can Google "javascript obfuscator" to find solutions that may make your code even more difficult to read (and could also introduce bugs). The best protection is to run some/all of your code server-side and send the results to the client, but that will increase your server costs.

Share this post


Link to post
Share on other sites

I have rewritten code from a deminified Javascript source once. It was really trivial.

Handle as much as possible on the server, making it harder for people to copy, as they have to emulate your back-end.

If your game isn't too complex, or needs to be very responsive, you can run the game on the server and use a dumb client.

Share this post


Link to post
Share on other sites
1 hour ago, semk said:

one thing to consider is if you use cordova and publish an app out of your html/js game then that's a pretty strong way of hiding the code since people with the app won't be able to break it down back to js 

Actually, you can.

If you download the apk and unzip it, your js files will be there.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.