Skip to content

SQLite Key Store

The SQLite key store persists encryption keys in a local SQLite database file. It is the recommended key store for local development — zero-config, no server dependencies, and keys survive application restarts.

Development Only

This key store stores raw key bytes in a SQLite file without envelope encryption, HSM backing, or access auditing. It is not suitable for production. For production, use a secrets manager: HashiCorp Vault, Azure Key Vault, or AWS KMS. If you need a self-managed production store, see the PostgreSQL key store with its Production Security Guide.

Installation

shell
dotnet add package Tayra.KeyStore.Sqlite
powershell
Install-Package Tayra.KeyStore.Sqlite

Setup

The simplest registration requires no configuration — keys are stored in tayra_keys.db in the working directory:

csharp
services.AddTayra(opts => opts.LicenseKey = licenseKey)
    .UseSqliteKeyStore();

To specify a custom file path:

csharp
services.AddTayra(opts => opts.LicenseKey = licenseKey)
    .UseSqliteKeyStore(opts =>
    {
        opts.ConnectionString = "Data Source=/path/to/my-keys.db";
    });

Configuration Options

PropertyTypeDefaultDescription
ConnectionStringstring"Data Source=tayra_keys.db"SQLite connection string.
TableNamestring"tayra_encryption_keys"Table name for storing encryption keys.
AutoMigratebooltrueWhen true, automatically creates the table on first use.

Table Schema

When AutoMigrate is enabled (the default), Tayra creates the following table on first use:

sql
CREATE TABLE IF NOT EXISTS tayra_encryption_keys
(
    key_id      TEXT NOT NULL PRIMARY KEY,
    secret_key  TEXT NOT NULL,
    created_at  TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
);

CREATE INDEX IF NOT EXISTS idx_tayra_encryption_keys_prefix
    ON tayra_encryption_keys (key_id);

Non-DI Usage

For the non-DI path via TayraHost.Create(), pass a SqliteKeyStore instance directly:

csharp
using var tayra = TayraHost.Create(
    opts => opts.LicenseKey = licenseKey,
    keyStore: new SqliteKeyStore(
        Options.Create(new SqliteKeyStoreOptions()),
        NullLogger<SqliteKeyStore>.Instance));

When to Use

ScenarioUse SQLite?
Local developmentYes — zero-config, persistent across restarts
CI/CD pipelinesYes — ephemeral .db file, no server needed
Unit testsNo — use the built-in InMemoryKeyStore (faster, no file I/O)
ProductionNo — use Vault, Azure Key Vault, or AWS KMS

.gitignore

Add the SQLite database file to your .gitignore to avoid committing encryption keys to source control:

tayra_keys.db
tayra_keys.db-wal
tayra_keys.db-shm

See Also