PVermeer / dexie-addon-suite-monorepo

MIT License
8 stars 0 forks source link

does dexie-encrypted-addon handle keeping the encryption secret key secure/safe? #33

Closed Damar225 closed 1 year ago

Damar225 commented 1 year ago

Hello, First thanks for this great library and its addon.

There is something that is not clear for me about the secret key and encryption, does dexie-encrypted-addon handle keeping the encryption secret key secure/safe?

I saw in the documentation that you are doing this: // Generate a random key const secret = Encryption.createRandomEncryptionKey();

Is doing the encryption this way will be safe/secure? or can any one inspect that secret key and use it to encrypt the database?

I'm using this library with Next.js, thanks.

PVermeer commented 1 year ago

Hi @Damar225,

Thanks for bringing this to my attention.

Encryption.createRandomEncryptionKey() Is just an implementation to generated a random key with the methods provided in tweetnacl-js. It's meant to generated a key on first usage. After that, you provide the key from a trusted source.

You are responsible for saving this key somewhere secure and use it when opening the database. To keep it secure in your app you could:

Since you're using Next.js you can provide it from the backend. Make sure it's not persistent on the client! Watch out for serverless databases with persistence enabled (e.g. Google's Firebase with offline first strategy).

After the key is provided, the app stores the key in memory. Your app should only know about the key after the user is verified.

I will update the docs with this information to make it more clear. If you still have any questions let me know.

Damar225 commented 1 year ago

Thanks, this is very helpful.