Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Now that I understand what you're saying, I can give you a firm answer :)</p> <p>The best I can tell you is that you can't get decent encryption in the way you're looking to do it. Private key encryption (namely RSA) uses very, very, very large numbers to do encryption. Using small numbers is very simple to crack computationally (there are only so many prime numbers) and the numbers get big extraordinarily quickly. Basically, with RSA, you need to take large numbers and raise them to large exponents. JavaScript is able to support quite large numbers, but you'll hit a wall with performance. With a 512-bit key, encryption of a few kilobytes can take up to a few seconds, while decryption can take seconds to minutes to do. The reason JS is so slow is simply because it's not a compiled language. Sure, you could decrease the key size, but anything larger than a couple kilobytes and you've got a problem.</p> <p>Also, RSA is inherently insecure in a web page because the private key is transmitted alongside the data to be decrypted (unless it was transferred earlier), which enables anyone that receives the page to decrypt the data.</p> <p>I'm going to assume that you're looking to do this because you want to obfuscate some code from your user or a client, so I'm going to recommend that you check out XOR encryption. Granted, it's nowhere near as secure as RSA, but it uses principles that can be very secure if used properly. For instance, if you use a random key that's used only once and has the same length as your data/code (an one-time pad), your encryption is "uncrackable". Even better, XOR encryption is FAST. Here are some resources:</p> <p><a href="http://guymal.com/mycode/xor_js_encryption/" rel="nofollow noreferrer">http://guymal.com/mycode/xor_js_encryption/</a></p> <p><a href="http://javascript.internet.com/passwords/xor-encryption4.html" rel="nofollow noreferrer">http://javascript.internet.com/passwords/xor-encryption4.html</a></p> <p>Hope you have luck with what you're trying to do!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload