I'm just learning to use SQLite and I was curious if such is possible:
Encryption of the database file?
Password protect opening of the database?
PS. I know that there is this "SQLite Encryption Extension (SEE).", but according to the documentation, "The SEE is licensed software...." and "The cost of a perpetual source code license for SEE is US $2000."
You can use SQLite's function creation routines (PHP manual):
When inserting data, you can use the encryption function directly and INSERT the encrypted data or you can use the custom function and pass unencrypted data:
When retrieving data, you can also use SQL search functionality:
It's certainly possible and there exist several open source solutions besides SEE. Among them the encryption extension coming with wxSQLite3. See my answer to a similar question for details.
Keep in mind, the following is not intended to be a substitute for a proper security solution.
After playing around with this for four days, I've put together a solution using only the open source System.Data.SQLite package from NuGet. I don't know how much protection this provides. I'm only using it for my own course of study. This will create the DB, encrypt it, create a table, and add data.
Optionally, you can remove
conn.SetPassword(passwordBytes);
, and replace it withconn.ChangePassword("password");
which needs to be placed afterconn.Open();
instead of before. Then you won't need the GetBytes method.To decrypt, it's just a matter of putting the password in your connection string before the call to open.
SQLite has hooks built-in for encryption which are not used in the normal distribution, but here are a few implementations I know of:
The SEE, SQLiteCrypt and SQLiteCrypto require the purchase of a license.
Disclosure: I created botansqlite3.
Well,
SEE
is expensive. HoweverSQLite
has interface built-in for encryption (Pager). This means, that on top of existing code one can easily develop some encryption mechanism, does not have to beAES
. Anything really. Please see my post here: https://stackoverflow.com/a/49161716/9418360You need to define SQLITE_HAS_CODEC=1 to enable Pager encryption. Sample code below (original
SQLite
source):There is a commercial version in
C language
forSQLite
encryption using AES256 - it can also work withPHP
, but it needs to be compiled withPHP
andSQLite
extension. It de/encryptsSQLite
database file on the fly, file contents are always encrypted. Very useful.http://www.iqx7.com/products/sqlite-encryption