1

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

JohnB
  • 3,921
  • 8
  • 49
  • 99
  • This has been asked before, though I don't know if you'll find the answers very satisfying. [Where is "SetPassword" or "ChangePassword" in SQLiteConnection class?](https://stackoverflow.com/questions/62294577/where-is-setpassword-or-changepassword-in-sqliteconnection-class) – Noah Apr 03 '21 at 00:38
  • SQLite itself doesn't support encryption. It's always provided by customized libraries like SQLCipher. This is explained in [the docs](https://learn.microsoft.com/en-us/dotnet/standard/data/sqlite/encryption?tabs=netcore-cli), which show how to use encryption through SQLCipher – Panagiotis Kanavos Jul 21 '21 at 14:13

1 Answers1

3

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)

scooter
  • 185
  • 1
  • 8
  • Added note for those of us who end up here eons later... I was getting errors with 112 only working in framework projects, ended up finding 1.0.106.0 works for framework, core and netstandard. – Jrdiver Aug 22 '23 at 17:40
  • Actually looks like one can get to 1.0.108.0. Lots of unlisted packages and trying to poke though to get things working. 108 works, 109 fails to connect. – Jrdiver Aug 24 '23 at 06:33