views:

452

answers:

3

I was thinking about creating a Web app that would let people enter text (using SSL connection) and it would be encrypted before saving to the DB. The goal would be to have it so that only users could decrypt it.

You could have the users enter the key along with their data, and enter it again when they want to see the data, and not store the key. That would be kind of painful for the user, though.

However, if you stored the key on the server you'd have access to it and could potentially decrypt their data.

I don't think it's possible to do it without either having the user enter the key every time or storing the key, but is there some way that I'm not thinking of? Like maybe generating a key from information only the user knows? Something involving cookies?

+9  A: 

You should look into public key cryptography. The basic idea is that you can encrypt information using a public key that only the holder of the private key can decrypt. In your scenario, the server would have a record of all the users' public keys and use them to encrypt the information. Then your users would use their private keys, which the server never sees, to decrypt the data.

If you're looking for a way to store the private key client-side, you could look into PersistJS.

Kyle Cronin
+4  A: 

Sounds like you could do something using PGP. As a previous post mentioned you would have a public and private key. The private key can be secured by a passphrase. That way you could have the private key potentially stored on the db, since it would still require a passphrase to use it.

The huge problem is that if the user should forget that passphrase, they could lose that data. You could get around that by using an Alternate Decryption Key (ADK). That key is automatically encrypted with everything and can be split between multiple individuals.

Rob Haupt
+1  A: 

From an information security perspective, this only makes sense if the encryption/decryption is done on the user's computer, and not your server (since there's no guarantee that you're not storing the key and/or the plaintext). JavaScript is out of the question, so you need a client application*.

Also, public-key cryptography is computationally expensive. You might want to keep that in mind if you have a lot of users and decide to do encryption/decryption on the server.

* or a Java applet, but that's so 90's. Silverlight or Flash could potentially work, too.

Can Berk Güder
JS is not out of the question. As long as the amount of data isn't large JS will do just fine. Here's an example of RSA in JS: http://www.ohdave.com/rsa/ My browser encrypts in about 10ms and decrypts in about 70ms on the page. Now, that was only a sentence, but it seems fast enough for basic use.
Kyle Cronin
Anyway you only use public key encryption to encrypt/decrypt a randomly generated key for symmetric encryption (AES for example) which is really fast.
Chochos
@Chocos: correct. Unless your plaintext is very short. But public-key cryptography is still expensive.
Can Berk Güder