更新时间:2023-11-07 21:36:28
根据这个答案保护EntityFramework核心应用程序使用的SQLite数据库
EF Core使用Microsoft.Data.Sqlite,目前不支持
加密开箱即用。请参阅
https://github.com/aspnet/Microsoft.Data .Sqlite /问题/ 184 。您可以
自己使用SQLite扩展添加加密。
在GitHub链接中,提供了其他链接, / p>
I use SQLite with Entity Framework.
I create the DB with following code:
class MyContext : DbContext
{
// DbSets, OnModelCreating(), etc.
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=c:\\test.db");
}
}
//this is in my test method
using (var db = new MyContext())
{
db.Database.EnsureCreated();
}
The above code works. The DB gets created. But I want to encrypt the DB by providing password in connection string:
optionsBuilder.UseSqlite("Data Source=c:\\test.db;Password=mypassword");
In this case, after EnsureCreated
is called, I get exception
An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll Additional information: Keyword not supported: 'password'.
What is wrong with using password? How can I encrypt that SQLite database?
According to this answer Protect SQLite database used by EntityFramework Core Application
EF Core uses Microsoft.Data.Sqlite, which does not currently support encryption out-of-box. See https://github.com/aspnet/Microsoft.Data.Sqlite/issues/184. You could add encryption yourself using SQLite extensions.
At the GitHub link provided there were other links to an alternative at