SQLCipher (Encrypted SQLite)
The Shiny.DocumentDb.Sqlite.SqlCipher package provides an encrypted SQLite provider using SQLCipher. It shares all query generation, expression translation, and LINQ support with the standard SQLite provider — the only differences are the native bundle and encryption-aware backup/rekey support.
-
Install the package
Terminal window dotnet add package Shiny.DocumentDb.Sqlite.SqlCipherThis replaces
Shiny.DocumentDb.Sqlite— do not install both. The SqlCipher package referencesMicrosoft.Data.Sqlite.Core(without the default unencrypted bundle) and addsSQLitePCLRaw.bundle_e_sqlcipherfor the SQLCipher native library. -
Register with dependency injection
using Shiny.DocumentDb.Sqlite.SqlCipher;services.AddSqlCipherDocumentStore("mydata.db", "mySecretKey");// or with full optionsservices.AddSqlCipherDocumentStore(opts =>{opts.DatabaseProvider = new SqlCipherDatabaseProvider("mydata.db", "mySecretKey");opts.TypeNameResolution = TypeNameResolution.FullName;opts.JsonSerializerOptions = new JsonSerializerOptions{PropertyNamingPolicy = JsonNamingPolicy.CamelCase};});Or instantiate directly:
// Quick setupvar store = new SqlCipherDocumentStore("mydata.db", "mySecretKey");// Full optionsvar store = new SqlCipherDocumentStore(new DocumentStoreOptions{DatabaseProvider = new SqlCipherDatabaseProvider("mydata.db", "mySecretKey")});
The constructor takes a file path and password as separate parameters so requirements are explicit. All other DocumentStoreOptions (table mapping, AOT, logging, etc.) work identically to the standard SQLite provider.
Rekeying
Section titled “Rekeying”Change the encryption key of an existing database using the RekeyAsync extension method on IDocumentStore. This issues PRAGMA rekey with SQL injection protection via SQLite’s quote() function.
using Shiny.DocumentDb.Sqlite.SqlCipher;
await store.RekeyAsync("newPassword");RekeyAsync throws InvalidOperationException if the store is not using SqlCipherDatabaseProvider.
Backup
Section titled “Backup”Backup works the same as the standard SQLite provider. The encryption password is automatically propagated to the backup database — the backup file will be encrypted with the same key.
await store.Backup("/path/to/backup.db");Differences from Shiny.DocumentDb.Sqlite
Section titled “Differences from Shiny.DocumentDb.Sqlite”Shiny.DocumentDb.Sqlite | Shiny.DocumentDb.Sqlite.SqlCipher | |
|---|---|---|
| Native bundle | bundle_e_sqlite3 (via Microsoft.Data.Sqlite) | bundle_e_sqlcipher (via SQLitePCLRaw.bundle_e_sqlcipher) |
| Encryption | Not supported | AES-256 via SQLCipher |
| Constructor | Connection string | File path + password |
| Backup | Unencrypted destination | Password propagated to destination |
| Rekey | N/A | store.RekeyAsync("newPassword") |
| Query/LINQ | Full support | Identical — inherits from SqliteDatabaseProvider |
| Package size | Smaller (no encryption native libs) | Larger (includes SQLCipher native binaries) |
When to use which
Section titled “When to use which”- Use
Shiny.DocumentDb.Sqlitewhen encryption is not needed — smaller package, simpler setup. - Use
Shiny.DocumentDb.Sqlite.SqlCipherwhen the database file must be encrypted at rest (mobile apps with sensitive data, HIPAA/PCI compliance, etc.).