Skip to content

Conversation

@ororsatti
Copy link

@ororsatti ororsatti commented Jul 31, 2023

ideally i'd like to avoid adding to the non-JSI version since its going to be less and less supported as we progress with JSI in RN.

TODO:

  • Add SQLCipher to Android
  • Add an option to select sqlite build (sqlite3/sqlCipher - this seem to be a requirement on the last PR trying to add sqlcipher) on Android
  • ADD SQLCipher to iOS
  • Add an option to select sqlite build (sqlite3/sqlCipher - this seem to be a requirement on the last PR trying to add sqlcipher) iOS
  • Change API to accept passphase.
  • Add sqlcipher amalgamation to nozbe workspace (same method as sqlite and simdjson) @radex
  • Fix iOS tests

Or Antonio Orsatti added 6 commits July 27, 2023 14:07
Changes:
- add a flag if using encrypted DB
- install openssl if using encrypted db
- add pathes to cipher amalgamation based on the flags.
- add openSSL lib
@ororsatti ororsatti changed the title Add sqlcipher to jsi Add encrypted SQLite to jsi Aug 1, 2023
@ororsatti ororsatti changed the title Add encrypted SQLite to jsi Add encrypted SQLCipher WatermelonDB JSI Aug 2, 2023
@ororsatti
Copy link
Author

@radex I can not seem to run the ios/android tests properly, any chance you help me with it?

@killerchip
Copy link

killerchip commented Jan 17, 2024

Hey guys,

Thanks for your great work on this, and thanks for the great library

Is this PR still alive? Is there still interest in Nozbe in adding encryption to the DB?
We are also looking into using WatermelonDB with encryption on native (Android mainly). But C++ is currently out of my league. Do you know how I can help?

I was able to make something work based on this PR #907, but of course, it does not support JSI.

@ororsatti, does your PR work? I just did a test, but it seems that the DB is not getting encrypted (Android).

@ororsatti
Copy link
Author

Hey guys,

Thanks for your great work on this, and thanks for the great library

Is this PR still alive? Is there still interest in Nozbe in adding encryption to the DB?
We are also looking into using WatermelonDB with encryption on native (Android mainly). But C++ is currently out of my league. Do you know how I can help?

I was able to make something work based on this PR #907, but of course, it does not support JSI.

@ororsatti, does your PR work? I just did a test, but it seems that the DB is not getting encrypted (Android).

I'm using it in several production apps, so yep.
I might be able to help talk to me this evening:
orsatti@skiff.com

@killerchip
Copy link

I'm using it in several production apps, so yep. I might be able to help talk to me this evening: orsatti@skiff.com

@ororsatti thank you very much for your valuable help on this. Indeed your PR works as expected.
As we discussed it would be awesome if this could turn into a separate WMDB adapter.

@radex would it be preferable to make it into a separate adapter? Or just as an option to the base SQLite adapter as is with this PR?

@ororsatti
Copy link
Author

I'm using it in several production apps, so yep. I might be able to help talk to me this evening: orsatti@skiff.com

@ororsatti thank you very much for your valuable help on this. Indeed your PR works as expected.
As we discussed it would be awesome if this could turn into a separate WMDB adapter.

@radex would it be preferable to make it into a separate adapter? Or just as an option to the base SQLite adapter as is with this PR?

I don't think making it an adapter is the right decision.
An adapter is the middle layer, what stands between your app, and the underlying SQLite.
Since I am not changing the platform, nor the api, I don't see a reason to change the adapter here.
It should be as it is, a flag on which you raise if you want to use it, and pass password if you desire.

@ororsatti
Copy link
Author

I'm using it in several production apps, so yep. I might be able to help talk to me this evening: orsatti@skiff.com

@ororsatti thank you very much for your valuable help on this. Indeed your PR works as expected.
As we discussed it would be awesome if this could turn into a separate WMDB adapter.

@radex would it be preferable to make it into a separate adapter? Or just as an option to the base SQLite adapter as is with this PR?

You can think about it like it's a car.
If you change the engine, but as long as it has the same gear, i.e the same API, you don't have to learn manual.
Same here, the api is the same, so no need to change the adapter.

@dlogvin
Copy link

dlogvin commented Oct 26, 2024

Hey! just wanted to check if this PR is still alive

@ororsatti
Copy link
Author

Hey! just wanted to check if this PR is still alive

im still maintaining it from time to time, but i don't think the lib owner merges community PRs...

@dlogvin
Copy link

dlogvin commented Nov 6, 2024

Hey! just wanted to check if this PR is still alive

im still maintaining it from time to time, but i don't think the lib owner merges community PRs...

That's quite sad. Adding encryption definitely is important, if not a requirement nowadays. Then I guess we have to fork 🫡

When I was looking at this library, I was hoping it had some sort of encryption capabilities, but I quickly left it as it came to my understanding that such a thing is probably not coming in the near future for this lib.

@ororsatti
Copy link
Author

ororsatti commented Nov 7, 2024

Hey! just wanted to check if this PR is still alive

im still maintaining it from time to time, but i don't think the lib owner merges community PRs...

That's quite sad. Adding encryption definitely is important, if not a requirement nowadays. Then I guess we have to fork 🫡

When I was looking at this library, I was hoping it had some sort of encryption capabilities, but I quickly left it as it came to my understanding that such a thing is probably not coming in the near future for this lib.

well this pr works, this pr in particular was used by me in production multiple times, and by a few more of the community... you can just use it. the conflicts doesn't seem that bad tbh

@kmye
Copy link

kmye commented Nov 9, 2024

i have tried to use the codes in this PR but there are build errors

e.g.

/mobile/ios/Pods/SQLCipher/sqlite3.h:1767:8: error: redefinition of 'sqlite3_mem_methods'
1767 | struct sqlite3_mem_methods {
|        ^
    In file included from /node_modules/@nozbe/watermelondb/native/ios/WatermelonDB/DatabasePlatformIOS.mm:1:
    In file included from /node_modules/@nozbe/watermelondb/native/shared/DatabasePlatform.h:5:
    In file included from /node_modules/@nozbe/watermelondb/native/shared/Database.h:7:

this seems to be caused by conflicting sqlite pod in my app, my app also include other libraries which includes sqlite and these could hgave caused the redefinition error. anyone has a solution this issue?

@rtripplanningbiz
Copy link

I'm using it in several production apps, so yep. I might be able to help talk to me this evening: orsatti@skiff.com

@ororsatti thank you very much for your valuable help on this. Indeed your PR works as expected. As we discussed it would be awesome if this could turn into a separate WMDB adapter.

@radex would it be preferable to make it into a separate adapter? Or just as an option to the base SQLite adapter as is with this PR?

Hi, how did you get it to encrypt in android? I haven't tried on IOS since I don't need it there. Android I am able to build but the database is not encrypted. Thanks!

@AlexanderDMitchell
Copy link

Hi, since securely storing a passphrase (e.g., with Expo SecureStore) requires asynchronous retrieval, how are you handling that with WatermelonDB’s initialization? Given that WatermelonDB is typically initialized at the top level where async/await can’t be used? Thanks

@MichelNassarFC
Copy link

any update on this?
its crucial to have encryptions

@ororsatti
Copy link
Author

Hi, since securely storing a passphrase (e.g., with Expo SecureStore) requires asynchronous retrieval, how are you handling that with WatermelonDB’s initialization? Given that WatermelonDB is typically initialized at the top level where async/await can’t be used? Thanks

hm? I had a user private key to work with. Didn't need to store anything?

@ororsatti
Copy link
Author

any update on this? its crucial to have encryptions

:(
just fork or something.

@annkiit2
Copy link

@radex Encryption with New Arch and jsi is a must now given encryption at rest is extremely important. Please give us a timeline on this. Using forks is risky

dmytech462 added a commit to pinginc/watermelon-db that referenced this pull request Jan 14, 2026
Based on PR Nozbe#1635 from Nozbe/WatermelonDB:
- Add SQLCipher amalgamation files
- Update native C++ to accept password parameter
- Add iOS SQLCipher support via podspec ($isEncryptedDB flag)
- Add Android SQLCipher support via build.gradle and CMakeLists.txt
- Add passphrase option to SQLiteAdapterOptions
jinsoo601 added a commit to pinginc/watermelon-db that referenced this pull request Jan 15, 2026
## Summary

This PR adds SQLCipher encryption support to WatermelonDB, enabling
encrypted SQLite databases on iOS and Android.

Based on Nozbe#1635, merged and
refined for our needs.

  Key changes:

  - New passphrase option in SQLiteAdapter to enable database encryption
- Bundled SQLCipher amalgamation (sqlite3.c/h) for native encryption
support
- Automatic plaintext database detection and wipe - when encryption is
enabled (passphrase provided) and an existing unencrypted database is
detected via isPlaintextSqlite(), the database files are automatically
wiped and recreated as encrypted. This prevents encryption errors when
switching from plaintext to encrypted mode.
- Optimized plaintext detection - reads only the first 16 bytes of the
file to check for SQLite header signature, avoiding full database open
- Fork configuration - updated package name to @pinginc/watermelondb and
URLs to pinginc repository for npm publishing

  Usage
```
  const adapter = new SQLiteAdapter({
    schema,
    passphrase: 'your-encryption-key', // enables SQLCipher encryption
  })
```
> [!NOTE] 
> 
> When passphrase is provided and the existing database is unencrypted
(plaintext), the database will be automatically wiped (deleted and
recreated). This happens because SQLCipher cannot open a plaintext
database with encryption enabled. Added to avoid crash errors. Ensure
you handle data migration or backup before enabling encryption on an
existing unencrypted database.

## Checklist

- [x] I have updated the summary to explain what's changed.
- [x] I have added unit and integration tests to cover the new
functionality.
- [x] I have followed the [PR
Guidelines](https://timebyping.atlassian.net/wiki/spaces/TECH/pages/1629126657/Pull+Request+PR+Guidelines).

---------

Co-authored-by: Jin Soo Lim <jinsoo601@gmail.com>
@nikitashmidt
Copy link

Hi, friend, I installed your package, but for some reason encryption isn't working. I set the isEncryptedDB variable to true, and I also saw encryptedDB in the code, which was also set to true. What could be the problem? How can I find the problem? Thank you very much for your work. @ororsatti

@ororsatti
Copy link
Author

Hi, friend, I installed your package, but for some reason encryption isn't working. I set the isEncryptedDB variable to true, and I also saw encryptedDB in the code, which was also set to true. What could be the problem? How can I find the problem? Thank you very much for your work. @ororsatti

Hello bud, I do not know exactly whats going on on your side, nor can I debug this remotely.
There were so many changes in this lib and in react native since I opened this pull request, so forgive me for not knowing what's going on.

I used to try and maintain this pr but since there seems to be no interest from the maintainers in this PR, I'm not going to invest any more time trying to keep it alive.

Very much sorry,
and feel free to give other libs a try, at the time I created it no one supported this feature, but now pretty much all major SQLite libs expose db encryption.

@annkiit2
Copy link

annkiit2 commented Jan 21, 2026

@radex Can you please look into @ororsatti 's PR ... This feature (Encryption) is very important especially when considering Offline first db

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants