0

I am hoping to be able to do this:

  1. Encrypt a string in the browser, with a password from the user
  2. Send that string to my server
  3. Allow anyone to request that string from my server
  4. The string can be decrypted by someone with the password
  5. Anyone without the password should need millions of dollars/years to decrypt the string

I've found this thread which uses AES to encrypt and decrypt a password. But testing it with my data, the decrypt function runs in 50 milliseconds. That'd be 1,728,000 password attempts in a day, just in the browser. If someone really wanted to break that encryption, I'm sure it'd be doable in short order.

My second intuition says that I should keep it on the server behind a password. You send the ID of the data you need, and the password, and it sends back your encrypted data. This solves the problem of #3, but I could still decrypt the data if I really wanted to.

Is there a way to do this were I, the server runner, doesn't need to be trusted? Assume the user can trust/validate what data they're sending to the server, and how it's encrypted in the browser.

Community
  • 1
  • 1
fnsjdnfksjdb
  • 1,653
  • 5
  • 19
  • 33
  • 1
    If you're trying to protect against brute-force key guessing, then you just need a long encryption key. The longer and more random the key (e.g. password in your case), the longer it takes to guess it. So, if you enforce a very long password and use a modern encryption algorithm (of which there are many), the data should be fairly secure. – jfriend00 Dec 25 '15 at 06:48

1 Answers1

0

Wait, I think I've figured it out.

The user would have a password, the hash for which would be sent to the server. The user can only access their data if they have the hash of their password.

The data would be encrypted with something like AES, but the key that's used for the encryption would also be the hash of their password. Suddenly 1,728,000 attempts/day seems tiny, because the password won't be in the dictionary or anything. It'll be a very long nonsense string.

Can anyone reading this confirm if that's the right approach?

fnsjdnfksjdb
  • 1,653
  • 5
  • 19
  • 33
  • 1
    If the hash algorithm is known (which it sounds like it would be if it's in the Javascript), then this just comes down to guessing the password, not guessing the hash. So, it all depends upon how long and unique the password is. Using the hash as you've proposed keeps the server from having to ever know the password (a good thing), but doesn't make the data any more secure if it's a weak password. – jfriend00 Dec 25 '15 at 06:51
  • @jfriend00 Would a slow password hashing algorithm help here? Something like bcrypt. It seems like it might... then for every password you want to try, you need to hash it first with a slow/computationally heavy algorithm. Thanks for helping me. – fnsjdnfksjdb Dec 25 '15 at 06:57
  • @jfriend00 Obviously complicated passwords would help even more, but would a slow hash help be an order of magnitude or two? – fnsjdnfksjdb Dec 25 '15 at 06:59
  • These types of functions are built in to php and node.js – wuno Dec 25 '15 at 07:02
  • 1
    Computationally intense hash operations don't hurt you, but a determined hacker can throw hardware at that problem to generate millions of hashes much faster than you might think so it isn't a solution all by itself. An unpredictable encryption key with a long length with a good, modern encryption algorithm is the way to be secure. If you're determined to avoid demanding a good, strong password, then this whole discussion hinges on what level of security compromise you're really willing to accept because you're refusing to do the single most important aspect of securing the data. – jfriend00 Dec 25 '15 at 07:02
  • @jfriend00 I'm not at all opposed to requesting a solid password. I'll definitely make that part of it. Just wanted to be sure the slow hash didn't solve things. – fnsjdnfksjdb Dec 25 '15 at 07:11
  • @jfriend00 is there a library you'd recommend that rates the quality of a password that you'd recommend? Or a set of requirements. – fnsjdnfksjdb Dec 25 '15 at 07:12
  • 1
    Lots of good reading material here: https://www.google.com/search?q=rating+quality+of+password – jfriend00 Dec 25 '15 at 07:19
  • Great, thank you. I'm looking at the zxcvbn library now. – fnsjdnfksjdb Dec 25 '15 at 07:33