I've posted this over at Stack Overflow but I think it's best suited here:

I'm making a web app where users will upload sensitive data (private finances records), so I want to encrypt one column in one table that holds the value.

If I understood correctly, I need to use a public key approach (instead of symmetric) because I want only for the users that created the data to be able to access it.

So, I need to generate a public a private key, using a password, and then encrypt the file using the public key.

Then I can decrypt it using the private key and the password. So I have a couple of questions:

  1. Where should the the public/private key and the password stored? I know I can store the public in the server since it doesn't need to be really secure: it's just used to encrypt, but where do I store the private key and password? Some resources I've read said store in the device but it doesn't make sense in the case right?

  2. I need to create a pair of public/private key and password for every user right?

  3. At which point do this keys/password need to be created? During user creation?

  • 1
    A warm welcome to the community. In this scenario there's two kinds of encryption - asymmetric and symmetric. Now for your questions: 1. Private key should be in the hands of the corresponding user. 2. Yes 3. Yes Jan 13 at 11:28
  • "because I want only for the users that created the data to be able to access it" - To access were? If you need that the server can access it, e.g. select some data based on some criteria, then you need to provide server with a key to decrypt. Then encryption makes no sense. If server doesn't need to decrypt data, then symmetric encryption will be sufficient: User will download the data and then decrypt them on the client side.
    – mentallurg
    Jan 13 at 15:12

1 Answer 1


Being that the same user will be encrypting and decrypting the sensitive data, you can use symmetric encryption instead of asymmetric encryption. With symmetric encryption (such as AES), the same key is used to encrypt and decrypt the data; as opposed to asymmetric encryption where you would have a public/private keypair.

The Web Crypto API can be used to implement encryption and decryption in javascript, so that all encryption takes place locally, in the user's web browser. This way, the server would only see the encrypted cyphertext, and never sees the plaintext of the encryption key.

As for where and how to store the encryption key - one method is to simply derive a key from a password, using a key derivation function such as bcrypt, pbkdf2, etc. This way, the key doesn't have to be stored at all. Another method is to create a random key, use a password to encrypt the random key, then store the encrypted key on the server.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .