Efcore: SQLCipher with the upcoming EF Core version: 3.0.0

Created on 18 Sep 2019  路  5Comments  路  Source: dotnet/efcore

I am in the process of updating our Microsoft.Data.Sqlite package, we are currently using v2.0.0. The transition to the official release 2.2.6 went smoothly, but I am considering delaying the update to use v3.0.0 when it is released. But we are using the bundle_sqlitecipher (and adding PRAGMA key after opening a connection) to enable database encryption and I was not able to figure out how to set it up to work with the current v3.0.0-rc1.19456.14.

After some digging, apparently the v3.0.0 comes with a dependency to SQLitePCL.raw v2.0.0 (#14824) but the latest bundle_sqlcipher is 1.1.14. Is my understanding correct that there is currently no way to use the new Password property in SqliteConnectionStringBuilder (#13828), since there is no provider which supports encryption?

I tried installing and uninstalling different sqlite bundle/provider NuGet packages but nothing worked. I always ended up either with a running app without encryption support, or after setting ExcludeAsssets:
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.0.0" ExcludeAssets="All" />

with and exception on SQLitePCL.Batteries_V2.Init(),

   v SQLitePCL.NativeLibrary.Load(String libraryName, Assembly assy, Int32 flags)
   v SQLitePCL.Batteries_V2.MakeDynamic(String name, Int32 flags)
   v SQLitePCL.Batteries_V2.DoDynamic_cdecl(String name, Int32 flags)
   v SQLitePCL.Batteries_V2.Init()
   v App.Wpf.Setup.InitializeFirstChance() ...

or trying SQLitePCL.Batteries_Init() but with a build error

The type 'Batteries' exists in both 'SQLitePCLRaw.batteries_sqlcipher ...' and 'SQLitePCLRaw.batteries_v2 ...'

So my final question is: is there a way to use the upcoming version 3.0.0 with database encryption? Do you know if there is upcoming bundle_sqlcipher v2.0.0 to support this?

Additional context

Microsoft.Data.Sqlite version: 3.0.0-rc1.19456.14
Target framework: WPF, .NET framework 4.7.2
Operating system: Windows 10

area-adonet-sqlite closed-external closed-question customer-reported

Most helpful comment

With the 2.0 release, the package id for bundle_sqlcipher changed to bundle_e_sqlcipher:

https://www.nuget.org/packages/SQLitePCLRaw.bundle_e_sqlcipher/

All 5 comments

With the 2.0 release, the package id for bundle_sqlcipher changed to bundle_e_sqlcipher:

https://www.nuget.org/packages/SQLitePCLRaw.bundle_e_sqlcipher/

Thank you @ericsink a quick answer I just got to try it. I was using information from SQLitePCL.raw wiki that may be why I didn't know that the bundle ID has changed for v2.

Anyway I was still not able to make it work even with the different bundle. I am still getting the same "Not found" exception as described above. Now I found out on the SQLitePCL.raw Release page for 2.0, that Xamarin.Mac is not supported right now which we will need to support in the future anyway so I am stuck with SQLite 2.2.6 for now.


From what from what I was able to deduce I think that some weird combination of NuGet packages might be the issue on my part, if you say that EFCore 3.0 works with SQLCipher for you. I tried stepping through the Batteries_V2.Init method (with JetBrains Rider) and method private static IntPtr MyLoad(...) searches for C:\Users\.....\Project.Wpf\bin\x86\Debug\runtimes\win-x86\native\e_sqlite3.dll which is not there (so it then throws "Not found" exception). The only DLL in that folder is "e_sqlcipher.dll". If I add either package Microsoft.Data.SQLite or bundle_green to the Wpf project, the file e_sqlite3.dll is there but the encryption disabled, which I guess is correct behaviour when the sqlcipher DLL is not actually used. But why Batteries{_V2}.Init() does not target the SQLCipher provider I am not able to figure out. I tried to add the provider packages explicitly but without a positive results I also did clean solution and remove packages folder many times to be sure that the changes have propagated.

If more people will have the same issue I am willing to help you and investigate more but I already spent too many work hours on this issue so I am going for the 2.2.6 version.

Ah, yes, I had problems with nuget packaging and the native builds for Xamarin.Mac. I do need to go back to that issue and try to find a workaround.

@danielkraut Can you submit an issue on SQLitePCL.raw to track this work?

@bricelam:

@danielkraut Can you submit an issue on SQLitePCL.raw to track this work?

SQLitePCL issue 297

Was this page helpful?
0 / 5 - 0 ratings