sqlite3.dart icon indicating copy to clipboard operation
sqlite3.dart copied to clipboard

Cross platform DB encryption

Open zs-dima opened this issue 3 years ago • 6 comments

Could be nice to be able to create encrypted DB in Web as well. Specially could be nice encrypt certain db(s) and others keep unencrypted.

zs-dima avatar Apr 05 '22 16:04 zs-dima

I've just realized that, since we control the file system on the web, we can do encryption on that layer instead of compiling SQLCipher for the web. I don't think this should be built into this library, but there could be an API for general file transformations happening during reads and writes. This API could then be used for encryption.

simolus3 avatar May 05 '22 15:05 simolus3

What about this project? https://github.com/sqlcipher/sqlcipher As documentation says it can be compiled similar to regular SQLite and have encryption built-in.

westito avatar May 05 '22 15:05 westito

That project can be compiled against a number of crypto libraries, but none of them was easy to compile to WASM for me. I thought about adding a crypto stub backed by WebCrypto through a Dart bridge and compile SQLCipher with that, but their build setup isn't really laid out for that. So I'd have to fork the project and keep up with changes, which I'm not really interested in. To compile sqlite3 to WASM, I just had to implement a documented VFS interface.

simolus3 avatar May 06 '22 10:05 simolus3

Yeah. The VFS level crypt would be much easier to implement with an encrypt library.

westito avatar May 06 '22 10:05 westito

I have been looking for a way to drop something like sqleet or the SQLite3MultipleCiphers project amalgation into the wasm build here to provide encryption for the web. It looks like the latter uses the VFS layer for encryption, I don't think it relies on any native encryption libs either. Would be interesting to see it as an alternative to SqlCipher for native libs also, instead of sqlcipher for encryption on native and something else for web.

nullrocket avatar Jul 19 '22 22:07 nullrocket

I have managed to get SQLite3MultiCiphers working for all platforms including the browser / wasm.

nullrocket avatar Aug 30 '22 16:08 nullrocket