问题
I'm knee deep in compilation for sqlite, system.data.sqlite, and xerial's JDBC trying to get an encrypted sqlite file working through all three. From my understanding, system.data.sqlite uses RC4 encryption, and SQLCipher/Rijndael/wxSqlite can use AES256.
Using this library, one can easily compile Windows binaries for AES256 encryption.
This library offers Xerial's JDBC by incorporating wxsqlite3's improvements, which it looks like is actually based on the above (Rijndael's) library.
Because the above two libraries are close to one-and-the-same, and use the same encryption, they have been compatible. I have a working Java project with the encryption-supporting JDBC, and I have a compiled sqlite3.dll and sqlite3shell.exe that allows me to use the command line to encrypt, read, write, etc databases. This sqlite dll and shell are compatible with the databases created with the JDBC.
Where I'm a bit lost is getting system.data.sqlite working with AES256. I need to use this library as it affords me the ability to use Entity Framework and LINQ. I had thought it would not be such an arduous task, but I've been ramming my head into a wall for the past few days on this issue. I have the encryption-ready sqlite3 dll, how do I merge this in with system.data.sqlite?
Thanks so much for any help.
回答1:
If you're targeting .NET standard 4.6.1+ or Core, you may want to give Microsoft.Data.Sqlite a try. This can give you AES256 encryption by simply adding 2 Nuget Packages. By the way, there are paid options to get AES256 compiled System.Data.Sqlite. Some are listed in this answer.
If your project is currently using System.Data.Sqlite, then transitioning will involve some search/replace of method & class names, much of which is a difference in caps. For example, "SQLiteDataReader" becomes "SqliteDataReader."
Another difference is that Microsoft.Data.Sqlite is strict about column naming. For example, a command that references a column named "DateListed" will fail if the database schema has that column as "Datelisted."
If you want to explore making a transition install 2 nuget packages:
Install-Package Microsoft.Data.Sqlite.Core
Install-Package SQLitePCLRaw.bundle_sqlcipher
Setup SQLitePCL
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlcipher());
SQLitePCL.Batteries_V2.Init();
SQLitePCL.raw.FreezeProvider();
Create encrypted database
string error = string.Empty;
static SQLitePCL.sqlite3 sqlite
SQLitePCL.raw.sqlite3_open(dbPath, out sqlite);
SQLitePCL.raw.sqlite3_exec(sqlite, "PRAGMA key ='myPassword'", out error);
SQLitePCL.raw.sqlite3_close(sqlite);
来源:https://stackoverflow.com/questions/48568617/compile-system-data-sqlite-with-aes256