The easiest way to build SQLite3 with encryption support on Windows. Compilation of DLL, SLL or shell is now a matter of minutes
*Support for 256 bit AES encryption is still experimental
Build script currently generates only solution (*.sln) files for Microsoft Visual Studio IDE, but as SQLite3 and wxSQLite3 are cross-platform, you may try to download the original wxSQLite3 source code and built it yourself for your platform.
premake.bat
or premake4.bat
Project -> Upgrade Solution
)Build -> Configuration Manager
and choose configurations and platforms you want to buildBuild -> Build Solution
, which should produce binaries in the bin
dirFollowing these steps and building all binaries in their Release versions took me ~2 minutes on my laptop.
Try to look for them here
Because developers of the wxSQLite extension needs to incorporate changes with every new version of SQLite, there is a time lag between a new version of SQLite and wxSQLite. If you want to update to the latest version of wxSQLite, you can do so in two ways:
premake update
or tools\update.bat
*Requires PowerShell
wxsqlite3-*/sqlite3/secure/src
dir from the archive to src
dir in the project root dir.VERSIONS
file in the repo root dir keeps an overview of versions of individual components provided in the repoThere are more ways how to add a native on-the-fly encryption layer to your SQLite3 DBs. Namely:
So after a few hours spent trying to build SQLCipher, I dived more deeply into the internet and found wxSQLite3, did some scripting to ease the build and this is the result.
#define SQLITE_HAS_CODEC
#include <sqlite3.h>
Set the key for use with the database
sqlite3_open
.sqlite3_key_v2
call performs the same way as sqlite3_key
, but sets the encryption key on a named database instead of the main database.
int sqlite3_key(
sqlite3 *db, /* Database to be rekeyed */
const void *pKey, int nKey /* The key, and the length of the key in bytes */
);
int sqlite3_key_v2(
sqlite3 *db, /* Database to be rekeyed */
const char *zDbName, /* Name of the database */
const void *pKey, int nKey /* The key, and the length of the key in bytes */
);
When opening an existing database, sqlite3_key
will not immediately throw an error if the key provided is incorrect. To test that the database can be successfully opened with the provided key, it is necessary to perform some operation on the database (i.e. read from it) and confirm it is success.
The easiest way to do this is select off the sqlite_master
table, which will attempt to read the first page of the database and will parse the schema.
SELECT count(*) FROM sqlite_master; -- if this throws an error, the key was incorrect. If it succeeds and returns a numeric value, the key is correct;
Change the encryption key for a database
pKey==0
or nKey==0
, the database is decrypted.sqlite3_rekey_v2
call performs the same way as sqlite3_rekey
, but sets the encryption key on a named database instead of the main database.
int sqlite3_rekey(
sqlite3 *db, /* Database to be rekeyed */
const void *pKey, int nKey /* The new key, and the length of the key in bytes */
);
int sqlite3_rekey_v2(
sqlite3 *db, /* Database to be rekeyed */
const char *zDbName, /* Name of the database */
const void *pKey, int nKey /* The new key, and the length of the key in bytes */
);
PRAGMA key='passphrase';
PRAGMA rekey='passphrase';
PRAGMA rekey='';
open // <-- db is still plain text
key // <-- db is now fully encrypted
use as usual
open // <-- db is fully encrypted
key // <-- db is still fully encrypted
use as usual // <-- read/written pages are fully encrypted and only decrypted in-memory
open // <-- db is fully encrypted
key // <-- db is still fully encrypted
rekey // <-- db is still fully encrypted
use as usual
open // <-- db is fully encrypted
key // <-- db is still fully encrypted
rekey with null // <-- db is now fully decrypted to plain text
use as usual