保护 UWP 应用中的 SQLite 数据库
Protect an SQLite database in an UWP app
它是一个使用 SQLite
数据库的 UWP
应用程序。下面是此应用程序的依赖项:
{
"dependencies": {
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
"Microsoft.Xaml.Behaviors.Uwp.Managed": "1.1.0",
"Newtonsoft.Json": "8.0.3",
"Template10": "1.1.*"
},
// ...
}
要求是:“[...]要有密码才能从应用程序或任何其他可以打开 SQLite
数据库的应用程序访问数据库".
Entity Framework Core 似乎不支持这种情况。 有什么建议吗?
看看 SQLCipher (https://github.com/sqlcipher/sqlcipher). It provides seamless full DB encryption with little overhead. It is a pain to build a VSIX for use with Visual Studio. If you do not want to build it yourself, yo can get a license from https://www.zetetic.net/sqlcipher/.
查看我的 Encryption in Microsoft.Data.Sqlite post 以获取有关使用 SQLCipher 和 Microsoft.Data.Sqlite 的朋友的提示。
将它与 EF Core 一起使用的最简单方法可能是使用与您的 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();
}
}
它是一个使用 SQLite
数据库的 UWP
应用程序。下面是此应用程序的依赖项:
{
"dependencies": {
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
"Microsoft.Xaml.Behaviors.Uwp.Managed": "1.1.0",
"Newtonsoft.Json": "8.0.3",
"Template10": "1.1.*"
},
// ...
}
要求是:“[...]要有密码才能从应用程序或任何其他可以打开 SQLite
数据库的应用程序访问数据库".
Entity Framework Core 似乎不支持这种情况。 有什么建议吗?
看看 SQLCipher (https://github.com/sqlcipher/sqlcipher). It provides seamless full DB encryption with little overhead. It is a pain to build a VSIX for use with Visual Studio. If you do not want to build it yourself, yo can get a license from https://www.zetetic.net/sqlcipher/.
查看我的 Encryption in Microsoft.Data.Sqlite post 以获取有关使用 SQLCipher 和 Microsoft.Data.Sqlite 的朋友的提示。
将它与 EF Core 一起使用的最简单方法可能是使用与您的 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();
}
}