10

I use Entity Framework Core 1.0 to manage an SQLite database in a C# desktop application. How to password-protect the database?

I know how using .NET class System.Data.SQLite, but how to do it using Entity Framework Core 1.0?

user4157124
  • 2,809
  • 13
  • 27
  • 42
  • Does this answer your question? [How to create a password protected database?](https://stackoverflow.com/questions/39903863/how-to-create-a-password-protected-database) – user4157124 Nov 20 '22 at 15:29

2 Answers2

11

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

parag
  • 2,483
  • 3
  • 20
  • 34
  • I have xamarin forms application and i try your method, but it doesn't work. I get this error when creating database: SQLite Error 1: 'cannot rollback - no transaction is active'. Can you help me? – Ahmed Shamel Feb 03 '18 at 20:59
2

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.

natemcmaster
  • 25,673
  • 6
  • 78
  • 100