diff --git a/README.md b/README.md index c657955..c4b3835 100755 --- a/README.md +++ b/README.md @@ -120,6 +120,29 @@ public ActionResult OnPostAsync() } ``` +## Encryption +To use SqliteCache with encryption make sure you are using the corresponding providers for your target framework. +E.g. for Net481: +* https://www.nuget.org/packages/SQLitePCLRaw.provider.sqlcipher/2.1.10 +* https://www.nuget.org/packages/SQLitePCLRaw.lib.e_sqlcipher/2.1.10 + +And make sure to use the correct provider when registering Sqlite +```csharp +raw.SetProvider((ISQLite3Provider)new SQLite3Provider_e_sqlcipher()); +serviceCollectionAccess.AddSingleton(); +serviceCollectionAccess.AddSingleton(aServiceProvider => aServiceProvider.GetRequiredService()); +``` + +then just configure SqliteCache with the PasswordOption +```csharp +serviceCollectionAccess.Configure(aSqliteCacheOptions => +{ +... + aSqliteCacheOptions.Password = password; +... +}); +``` + ## License SqliteCache is developed and maintained by Mahmoud Al-Qudsi of NeoSmart Technologies. The project is diff --git a/SqliteCache/SqliteCacheOptions.cs b/SqliteCache/SqliteCacheOptions.cs index 49bd4be..5fdaf97 100755 --- a/SqliteCache/SqliteCacheOptions.cs +++ b/SqliteCache/SqliteCacheOptions.cs @@ -39,6 +39,15 @@ public string CachePath } } + /// + /// Use this to specify a password for the SqliteConnection that is to be created. + /// If no is set, the connectionStringBuilder will not use the "Password" option. + /// + /// CAREFUL! this option will break your SqliteConnection if the sqliteProvider that you are using does not support encryption. + /// You will have to use e.g. (SQLitePCLRaw.provider.sqlcipher) instead of (SQLitePCLRaw.provider.e_sqlite3) + /// + public string? SqliteEncryptionPassword { get; set; } = null; + /// /// Specifies how often expired items are removed in the background. /// Background eviction is disabled if set to null. @@ -56,6 +65,12 @@ internal string ConnectionString Cache = SqliteCacheMode.Shared }; + // only set the password option if the user actually set a Password + if (!string.IsNullOrEmpty(SqliteEncryptionPassword)) + { + sb.Password = SqliteEncryptionPassword; + } + return sb.ConnectionString; } }