且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

保护UWP应用中的SQLite数据库

更新时间:2023-02-27 08:01:18

请参阅我的在Microsoft.Data.Sqlite中加密帖子,以获取有关在Microsoft.Data.Sqlite中使用SQLCipher和朋友的提示。

See my Encryption in Microsoft.Data.Sqlite post for tips on using SQLCipher and friends with Microsoft.Data.Sqlite.

在EF Core中使用它的最简单方法可能是在您的 DbContext 中使用开放连接。

The easiest way to use it with EF Core is probably to use an open connection with your DbContext.

class MyContext : DbContext
{
    SqliteConnection _connection;

    protected override void OnConfiguring(DbContextOptionsBuilder options)
    {
        _connection = new SqliteConnection(_connectionString);
        _connection.Open();

        var command = _connection.CreateCommand();
        command.CommandText = "PRAGMA key = 'password';";
        command.ExecuteNonQuery();

        options.UseSqlite(_connection);
    }

    protected override void Dispose()
    {
        _connection?.Dispose();
    }
}