Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protect SQLite database used by EntityFramework Core Application

I'm trying to use EntityFramework Core 1.0 (new name for EntityFramework 7) to manage an SQLite database in a C# Desktop application.

I read official documentation and my test-application works.

My question is: is it possibile to password-protect the database?

I know that there are lot of way to do it, it exists also the .NET class System.Data.SQLite that allow to do that, but how to do it using EFCore 1?

I can't understand if it is possible.

Thanks for help,

Enrico

like image 632
Enrico Brugnatelli Avatar asked Jan 28 '16 11:01

Enrico Brugnatelli


2 Answers

With EntityFramework Core 2.0 (EFCore 2.0), It is possible to use Encrypted SQLite database.

Steps for using SQLite Encrypted (SQLCiher) database with EFCore

  1. Add the reference of Microsoft.EntityFrameworkCore.Design in your project.

  2. Add the reference of Microsoft.EntityFrameworkCore.Sqlite.Core. This is really important step. Don't add the reference of Microsoft.EntityFrameworkCore.Sqlite. Otherwise it will not work.

  3. Add the reference of SQLitePCLRaw.bundle_sqlcipher. For encryption it is required. Add the following line ExcludeAssets="All" is important otherwise it will not work. For details refer to following link http://www.bricelam.net/2016/06/13/sqlite-encryption.html

    Download the working example from Github

like image 199
parag Avatar answered Sep 22 '22 01:09

parag


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.

like image 27
natemcmaster Avatar answered Sep 25 '22 01:09

natemcmaster