Jump to content

How to Encrypt JavaScript Code?


pinkyponky
 Share

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.

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

  • 2 weeks later...
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.

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...