.NET+Sqlite如何支持加密
.NET+Sqlite如何支持加密
Sqlite
SQLite
来源于公共领域 SQLite Is Public Domain
、
确保代码不会受到任何专有或许可内容的污染,没有任何来自互联网上的未知来源复制。即全是原创的。
虽然是免费的,无需许可证,可用于任何目的,但如果你的公司必须要一个许可证,你也能申请授权https://域名/purchase/license.
但不支持加密。如果想支持登录加密,需要另外的扩展SQLite 加密扩展(SQLite Encryption Extension,),具有读取/写入 AES 加密数据库的附加功能。具体授权可参考 https://域名/域名
Sqlite加密
一直以来,FreeSql
开发群中,总会有一些开发者来询问Sqlite
加密的问题,事实上,官方提供的Sqlite加密功能是收费的。当连接串上使用Password
时,会提示授权问题。
如果底层依赖于域名域名
,
Could not load file or assembly \'域名域名nse,
Version=域名.5, Culture=neutral, PublicKeyToken=433d9874d0bb98c5,
processorArchitecture=MSIL
如果底层依赖于域名te
也会提示
You specified a password in the connection string, but the native SQLite
library \'e_sqlite3\' doesn\'t support encryption.
域名域名
创建一个控制台项目,起名 域名teSystemCore
dotnet new console -n 域名teSystemCore
cd 域名teSystemCore
安装包
dotnet add package 域名域名
使用SQLiteConnection
创建一个连接,使用Password指定密码
using 域名te;
static void Open()
{
string baseConnectionString = "Data Source=域名";
var connectionString = new SQLiteConnectionStringBuilder(baseConnectionString)
{
Password = "123qwe"
}.ToString();
using SQLiteConnection? connection = new SQLiteConnection(connectionString);
域名();
}
Open();
运行项目
dotnet run
就会出现如下错误。
域名NotFoundException:“Could not load file or assembly
\'域名域名nse, Version=域名.5, Culture=neutral, PublicKeyToken=433d9874d0bb98c5, processorArchitecture=MSIL\'.
系统找不到指定的文件。”
域名te
创建一个控制台项目,起名 域名teMicrosoft
dotnet new console -n 域名teMicrosoft
cd 域名teMicrosoft
安装包
dotnet add package 域名te
使用SqliteConnection
创建一个连接,使用Password指定密码
using 域名te;
static void Open()
{
string baseConnectionString = "Data Source=域名";
var connectionString = new SqliteConnectionStringBuilder(baseConnectionString)
{
Mode = 域名WriteCreate,
Password = "123qwe"
}.ToString();
using SqliteConnection? connection = new SqliteConnection(connectionString);
域名();
}
Open();
运行项目
dotnet run
就会出现如下错误。
Unhandled exception. 域名lidOperationException: You specified a password in the connection string,
but the native SQLite library
\'e_sqlite3\' doesn\'t support encryption. at 域名域名()
其实微软已经提供了加密的方案。
- https://域名/zh-cn/dotnet/standard/data/sqlite/encryption?tabs=netcore-cli
dotnet remove package 域名te
dotnet add package 域名域名
dotnet add package 域名le_e_sqlcipher
重新运行项目 ,就会发现,他正常执行。没有任何报错。
有关使用不同的本机库进行加密的详细信息,请参阅自定义 SQLite 版本。
我们从 自定义 SQLite 版本上可以看到。
默认情况下,主 域名te
包引入 域名le_e_sqlite3
。 若要使用不同的捆绑,请改为安装 域名域名
包以及要使用的捆绑包。
域名le_e_sqlcipher
提供 SQLCipher 的非官方开放源代码内部版本。此版本支持加密。
完整代码
- https://域名/luoyunchong/dotnetcore-examples/blob/master/Database-Drivers/域名teMicrosoftCore/域名