使用Entity Framework Core进行密码保护的SQLite [英] Password protected SQLite with Entity Framework Core

查看:88
本文介绍了使用Entity Framework Core进行密码保护的SQLite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个受密码保护的SQLite数据库,以便在使用Entity Framework Core的WPF应用程序中使用它。

I am trying to create a password protected SQLite database, in order to used it within a WPF application using Entity Framework Core.

我了解如何生成我的数据库现有SQLite DB的DbContext和实体(数据库优先方法),但我无法将其与受密码保护的数据库一起使用。

I find out how to generate my DbContext and Entities from an existing SQLite DB (database first approach) but I can't get it working with password protected DB.

实际上,我什至不确定如何创建受密码保护的SQLite数据库。

Actually, I am not even sure of how to create a password protected SQLite DB. What is the difference between an encrypted db and a password protected db ?

推荐答案

根据此文章和此问题,尚无法(尚未?)使用Microsoft.Data.Sqlite程序集(由 EF Core使用)对数据库进行加密)。

According to this article and this issue, there is no way (yet?) to encrypt the database using the Microsoft.Data.Sqlite assembly (used by EF Core).

基于此,这是我为使其与 EF Core一起使用而要做的事情

Based on this, here is what I've done to get it working with EF Core:

var conn = new SQLiteConnection(@"Data Source=yourSQLite.db;");
conn.Open();

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

optionsBuilder.UseSqlite(conn);


使用<$非常重要c $ c> SQLiteConnection (可以管理加密数据库)来自 System.Data.SQLite.Core 程序集,而不是 Microsoft.Data.Sqlite > SqliteConnection 。

It is very important to use the SQLiteConnection (which can manage encrypted database) from the System.Data.SQLite.Core assembly and not the SqliteConnection from Microsoft.Data.Sqlite.

根据本文,您可能会通过替换 sqlite3.dll 使用内置的 SqliteConnection 由另一个处理加密数据库的组件在 Microsoft.Data.Sqlite 组件中交付(您可以在此存储库)。但是我没有对其进行测试。

According to the article, you could probably used the built in SqliteConnection by replacing the sqlite3.dll shipped within the Microsoft.Data.Sqlite assembly by another one that handle encrypted database (you can find a free one on this repo). But I did not tested it.

这里是如何做到这一点!

这篇关于使用Entity Framework Core进行密码保护的SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆