Score:0

Is it safe to store AES-KW encrypted key in database?

br flag

Use Case:

Web application accessed in browser. Registered users can store personal notes in the application, these notes are stored in a SQL database on a online server. The user can store unencrypted notes and encrypted notes. For unencrypted notes the process is trivial, just store the notes in the database. For encrypted notes the storage gets complicated (for me).

Frameworks:

Why should I use these Frameworks? I want that the encryption and decryption of the notes happens only on the client, so that the server has zero knowledge of the notes contents. I researched quite some time and found these libraries, scrypt and tweetnacl libraries are used by threema messanger afaik, so i consider them secure.

Protocol (outline):

Key generation, once per user:

  1. Use scrypt to derive a key encryption key from a user provided password, which should be different from the account password (the account password is hashed with Argon2 btw).
  2. Store the scrypt salt in the database
  3. Generate a NaCL key for note encryption
  4. Encrypt the NaCL key with AES-KW and the scrypt key encryption key and store it in the database

Encrypting/Decrypting notes:

  1. Load scrypt salt from database
  2. Load wrapped NaCL key from database
  3. Generate key encryption key from password and scrypt salt
  4. Unwrap NaCL key
  5. Encrypt note with unwrapped NaCL key and unique nonce
  6. store ciphertext and nonce in the database

As far as I know there is no secure way to permanently store the NaCL key of the user permanently on the device (browser), because of other users that might use the device or just some javascript code.

Question:

Is it secure to store the users NaCL key encrypted with AES-KW through the scrypt generated key encryption key in the database?

jp flag
Safe from what?
Michael avatar
br flag
For example. Given a strong user password, is the AES-KW wrapped key safe from being decrypted if the database gets stolen. More generally, is there a better way to achieve my goal without the need to save the key in the database even if encrypted.
jp flag
the wrapped key can't be unwrapped by someone who doesn't know the key to unwrap it - that's the point
Michael avatar
br flag
Ok thank you, I was just curious if it is considered bad practice to store this wrapped key in the database.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.