I don't want the server to ever see the raw input and would rather have the client do the encryption and then pass the data (over https) to the server for storage.
If I use a JS library to AES encrypt it what other things do I have to look out for?
I don't want the server to ever see the raw input and would rather have the client do the encryption and then pass the data (over https) to the server for storage.
If I use a JS library to AES encrypt it what other things do I have to look out for?
When this question was asked in 2014, the Web Crypto API did not yet exist. But, now that we have the Web Crypto API, you may want to consider using it instead of one of the libraries referenced in the other answers on this page, for doing in-browser crypto. The Web Crypto API has a CSPRNG implementation, as well as implementations of most common symmetric encryption, asymmetric encryption, hashing, and HMAC functions, all of which you can call from javascript.
However, this still doesn't solve the age-old 'chicken-and-egg' problem when it comes to browser-crypto: `If you can't trust the server with your secrets, then how can you trust the server to serve you secure code?'
JavaScript crypto is generally considered a bad idea (see details here )
If you're trying to address the threat of the server being malicious, then the first problem you encounter is "where does the JavaScript that does the encryption come from"?
The usual answer for websites is, "it comes from the server", which leaves you with the problem that if the server is malicious they can just change the JavaScript to give them a a copy of the key required to decrypt the data.
This makes the JavaScript crypto kind of pointless...
The recent CIA leaks (and to a lesser extent, Snowden revelations earlier) have convinced me that @rоry-mccune's answer (which I previously believed in as well) is no longer good advice. CIA documents say that protocol downgrade attacks render HTTPS on its own ineffective. Furthermore it's quite possible that even if a party has a servers private keys (enabling both HTTPS surveillance AND alteration / forging) they may not wish to risk revealing that they have the private keys by altering the content via a MITM attack, since the changed content could be detected. Also note that passive surveillance can lead to active compromise. For example, if a password or access token is sent to the server an attacker can then use that password to get further access while not giving away that they've broken a cipher or implemented a passive protocol downgrade attack (passive because they're only surveilling (not altering / forging) - presumably in a dragnet or as part of a botnet of hacked routers / wifi points).
Also, generating a private key client side, sending the public key along with the encrypted message and deleting (or periodically replacing) the private key client side ensures a greater degree of forward secrecy in the event that a cypher is broken.
Other than possibly performance in certain contexts, I fail to see the downside of client side encryption. Yes CSP, preloaded HSTS, and HPKP, TLS 1.2+ are more important and yes if you're pulling in code from elsewhere it can mess with your runtime and yes the random number generator may not be pure enough but the entire argument is hinged on this quote from the linked article:
You can. It's harder than it sounds, but you safely transmit Javascript crypto to a browser using SSL. The problem is, having established a secure channel with SSL, you no longer need Javascript cryptography; you have "real" cryptography. Meanwhile, the Javascript crypto code is still imperiled by other browser problems.
Which the CIA says is not true in leaked classified documents.
Furthermore the Snowden leaks showed how in many instances governments would use lazy dragnets for most sites and targeted attacks for a few (like Google) that were secure enough to cause trouble. If a cipher is secretly broken you'll be better protected by implementing this than if you didn't.
As for what to recommend specifically, I haven't taken the time to vet the alternatives. The author of the linked article mentions this but now that we have what is trying to be a secure random number generator in Chrome and Firefox I think on the whole we're better off trying to encourage more open source developers to secure things than to not try to do so. Just make sure they know it's important to still have TLS.