Compile System.Data.Sqlite With AES256 - encryption

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.

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);

Related

Does the latest version of System.Data.Sqlite not support password encryption?

I've got a .Net Core appl and am using the System.Data.SQLite.dll package to connect to a SQLite DB.
I'm trying to encrypt the database with a password.
In version 1.0.93.0 of System.Data.SQLite.dll library I can set or change the password encryption of the database:
SQLiteConnection con = new SQLiteConnection($"Data Source=DBName;Version=3;");
conn.SetPassword($"{password}");
conn.ChangePassword($"{password}");
conn.Open();
In the latest version 1.0.113.7 the api's no longer to appear to be supported.
Visual Studio throws a compiler error on the SetPassword() and ChangePassword() calls.
How do I password encrypt my databases?
Is there another way to achieve this using this library (or something similar)?
Yes, it seems that starting with System.Data.SQLite version 1.0.113.0, support for encryption in this way was entirely removed in this checkin, by modifying the file /Targets/SQLite.NET.Settings.targets, and setting the value of InteropCodec to false.
Specifically the comment says "Merge all changes needed for the SQLite core library 3.32.0 release."
This reveals to us that the actual culprit is SQLite itself, where in release 3.32.0, they removed support for this type of encryption API as well, in this commit, where the comment says "simplify the code by removing the unsupported and undocumented SQLITE_HAS_CODEC compile-time option"
Neither the change in System.Data.SQLite nor in SQLite are documented in the release notes for these projects.
In prior versions of System.Data.SQLite, such as 1.0.112.1 and earlier, encryption via the SetPassword() method was supported, and this used the “SQLite Encryption Extension” (SEE)

Does rocksdbjava api library contain the rocksdb database itself

I am very new to rockdb and will be using the rocksdb in my application as a lookup service. Does the rockDBjava library api provided contain the database itself, I mean is it not necessary to install rocksDB database separately.
I tried running the code using library and see some files created in the db path I mentioned in code, so not sure how exactly it works and if I need to install DB separately or if the library stores data in the directory and it itself acts as database?
No, you should not need to install RocksDB separately if you already have RocksJava working. They're not very clear on stating that, but if you look at the wiki in their Git repo you'll find this:
RocksJava is structured in 3 layers:
The Java classes within the org.rocksdb package which form the
RocksJava API. Java users only directly interact with this layer.
JNI code written in C++ that provides the link between the Java API
and RocksDB.
RocksDB itself written in C++ and compiled into a native library which
is used by the JNI layer.
That third point is basically their way of saying that RocksDB itself is one of the layers of RocksJava.

EntityFramework 7 - CodeFirst - SQLite - Manage DB using ApplyMigrations at runtime

I am well on my way to utilizing EF7 CodeFirst with SQLite...but really want to employ DB Migrations at runtime. This is a desktop application (Click-once deployment) meant to sync with a main database when connection is available, and provide offline data when no connection is present.
I have pulled down the nuget pre-release versions and all is working, except I cannot find any documentation of how to apply the migrations at runtime. I can successfully Add-Migrations and manually Apply-Migrations...but need a way to programatically Apply-Migrations at runtime.
I've also browsed the EF7 open-source project, but could not get anywhere there.
Versions I'm using: Latest Pre-release as of 9/15/2015
EntityFramework.Sqlite v7.0.0-beta7
EntityFramework.Relational v7.0.0-beta7
EntityFramework.Commands v7.0.0-beta7
...et al...you get the picture.
I am asking for help to apply runtime migrations...or what is the documented/recommended path for programatically maintaining a local/embedded db using EF7 CodeFirst SQLite?
UPDATE:
I went back to EF6 with SQLite but then found out that there is not SQLMigrationGenerator for SQLite.
EDIT:
I believe ApplyMigrations() method referenced in one of the notes has been deprecated. Searching the repository, there is no reference to "ApplyMigrations".
Today you can invoke the extension method Migrate on the DatabaseFacade.
This method is only available when the using Microsoft.Data.Entity statement is present. It comes from the RelationalDatabaseFacadeExtensions class that is part of the EntityFramework.Relational package.
Still have to find out how to migrate up and down from the API.

SQLite: A library supporting it implements it?

I started using SQLite for my project and I found there are many libraries supporting it like Qt, pysqlite, Poco C++ etc. I also found out that previous SQLite versions didn't support foreign keys.
How do the drivers know what sqlite executable to use? And how do I know they support what version of sqlite they support?
Another question: How do I enable foreign keys in sqlite by default?
The answer is: it depends.
Some applications will use a statically linked sqlite, others will link dynamically against the .dll or .so (depending on your OS). And of the ones linking against the dynamic library, whether it uses a system-wide or application-folder version depends on the application.
I (thankfully) haven't seen any apps that go through the sqlite.exe.
You need to issue pragma command to enable it
SQLite manages the foreign keys, not the ad-hoc library. Each library (if they are half-decent) will have their documentation which will list what version of SQLite is supported.
To determine if foreign keys are turned on in SQLite:
PRAGMA foreign_keys;
To turn on foreign keys:
PRAGMA foreign_keys = ON;
EDIT: This must be turned on not only before database creation, but at every connection for SQLite to activate foreign keys and their magic. (This is because foreign keys are not legacy, but is expected to change).

How to generate entity framework model from client side?

Can I generate entity framework model by clicking button in browser in client-side and save it back to web server PC?
EdmGen is the way to go if you're sure this is the best solution to your problem: http://msdn.microsoft.com/en-us/library/bb896270.aspx
If you're having problems with it could you please post the command line arguments you're using to call it?
You'll have to create a process in your web app (System.Diagnostics.Process) in order to kick off the executable from the browser side.
As David Neale says EmdGen is an option, if that is really what you want.
There is also EmdGen2, which has the advantage that it is able to work directly with the Edmx file:
EdmGen2 is a command-line tool for the
Microsoft ADO.NET Entity Framework.
The tool can be used as a replacement
for the EdmGen.exe tool that ships
with the .Net framework 3.5 SP1.
EdmGen.exe can only read and write the
CSDL, SSDL & MSL file formats.
However, EdmGen2.exe can read and
write the EDMX file format used by the
Visual Studio design tools.
Additionally, EdmGen2.exe can
translate between EDMX and CSDL, SSDL
& MSL formats, and the source code can
act as examples on using the tooling
APIs defined in the
System.Data.Entity.Design assembly.
Additionaly, EdmGen2.exe contains some
experimental functionality not found
in EdmGen.exe. Ankit Malpani, an
intern with Microsoft Research in
summer of 2008, and James Terwilliger,
a Post Doc researcher with MSR,
updated EdmGen2.exe with the ability
to identify inheritance
relatationships in relational database
schema. You can access this
functionality by using the
"RetrofitModel" option. The
RetrofitModel option connects to a
database instance and constructs an
EDM model (csdl, msl, ssdl, and edmx
files) that includes inheritance. The
tool uses data mining techniques to
identify TPT and TPH patterns in the
database instance, as well as vertical
partitioning, and constructs a
suitable model and mapping. To use the
tool, launch EdmGen2 with the
following arguments:

Resources