Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<SqliteCache>();
serviceCollectionAccess.AddSingleton<IDistributedCache, SqliteCache>(aServiceProvider => aServiceProvider.GetRequiredService<SqliteCache>());
```

then just configure SqliteCache with the PasswordOption
```csharp
serviceCollectionAccess.Configure<SqliteCacheOptions>(aSqliteCacheOptions =>
{
...
aSqliteCacheOptions.Password = password;
...
});
```

## License

SqliteCache is developed and maintained by Mahmoud Al-Qudsi of NeoSmart Technologies. The project is
Expand Down
15 changes: 15 additions & 0 deletions SqliteCache/SqliteCacheOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ public string CachePath
}
}

/// <summary>
/// Use this to specify a password for the SqliteConnection that is to be created.
/// If no <see cref="SqliteEncryptionPassword"/> 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)
/// </summary>
public string? SqliteEncryptionPassword { get; set; } = null;

/// <summary>
/// Specifies how often expired items are removed in the background.
/// Background eviction is disabled if set to <c>null</c>.
Expand All @@ -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;
}
}
Expand Down