All Projects → rindeal → Sqlite3 Encryption

rindeal / Sqlite3 Encryption

Licence: other
The easiest way to build SQLite3 with encryption support on Windows. Compilation of DLL, SLL or shell is now a matter of minutes

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Sqlite3 Encryption

Choochoo
Training Diary
Stars: ✭ 186 (+82.35%)
Mutual labels:  database, sqlite, sqlite3
Pydbgen
Random dataframe and database table generator
Stars: ✭ 191 (+87.25%)
Mutual labels:  database, sqlite, sqlite3
Esp32 arduino sqlite3 lib
Sqlite3 Arduino library for ESP32
Stars: ✭ 167 (+63.73%)
Mutual labels:  database, sqlite, sqlite3
D2sqlite3
A small wrapper around SQLite for the D programming language
Stars: ✭ 67 (-34.31%)
Mutual labels:  database, sqlite, sqlite3
Denodb
MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
Stars: ✭ 498 (+388.24%)
Mutual labels:  database, sqlite, sqlite3
Better Sqlite3
The fastest and simplest library for SQLite3 in Node.js.
Stars: ✭ 2,778 (+2623.53%)
Mutual labels:  database, sqlite, sqlite3
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (+1142.16%)
Mutual labels:  database, sqlite, sqlite3
Perfect Sqlite
A stand-alone Swift wrapper around the SQLite 3 client library.
Stars: ✭ 42 (-58.82%)
Mutual labels:  database, sqlite, sqlite3
Squeal
A Swift wrapper for SQLite databases
Stars: ✭ 303 (+197.06%)
Mutual labels:  database, sqlite, sqlite3
Mikro Orm
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.
Stars: ✭ 3,874 (+3698.04%)
Mutual labels:  database, sqlite, sqlite3
Android dbinspector
Android library for viewing and sharing in app databases.
Stars: ✭ 881 (+763.73%)
Mutual labels:  database, sqlite, sqlite3
Fluent Sqlite Driver
Fluent driver for SQLite
Stars: ✭ 51 (-50%)
Mutual labels:  database, sqlite, sqlite3
Sqlite Web
Web-based SQLite database browser written in Python
Stars: ✭ 1,169 (+1046.08%)
Mutual labels:  database, sqlite
Ebean
Ebean ORM
Stars: ✭ 1,172 (+1049.02%)
Mutual labels:  database, sqlite
Pyrustic
Lightweight framework and software suite to help develop, package, and publish Python desktop applications
Stars: ✭ 75 (-26.47%)
Mutual labels:  database, sqlite
Dbmigrations
A library for the creation, management, and installation of schema updates for relational databases.
Stars: ✭ 67 (-34.31%)
Mutual labels:  database, sqlite
Liszt
A personal organization software with a script engine for automation
Stars: ✭ 72 (-29.41%)
Mutual labels:  sqlite, sqlite3
Sqlite3 Ocaml
OCaml bindings to the SQLite3 database
Stars: ✭ 77 (-24.51%)
Mutual labels:  database, sqlite3
Electron With Sqlite3
Sample application for ElectronJS working with Sqlite3
Stars: ✭ 83 (-18.63%)
Mutual labels:  sqlite, sqlite3
Sqlite orm
❤️ SQLite ORM light header only library for modern C++
Stars: ✭ 1,121 (+999.02%)
Mutual labels:  sqlite, sqlite3

SQLite3 with encryption

What?

  • SQLite3 with a key based transparent encryption layer (128/256*-bit AES), which encrypts everything including metadata
  • drop-in/drop-out
    • you may for example encrypt your current databases, use them as long as you wish, then decide to decrypt them back to plain text and use them from the standard SQLite3 library, also you may use this library just as a standard SQLite3 library
  • no external dependencies like OpenSSL, Microsoft Visual C++ Redistributable Packages, Microsoft .NET Framework, ...

*Support for 256 bit AES encryption is still experimental

How to?

Compile it

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.

1. Requirements

2. Steps

  1. Download snapshot of this repository, unzip and open it
  2. Run premake.bat or premake4.bat
  3. The script should generate a solution file (.sln) in the project root dir, open it in VS as usual and upgrade the solution when needed, eg. if you have VS2013 and the script created VS2012 solution (automatic prompt or Project -> Upgrade Solution)
  4. Build -> Configuration Manager and choose configurations and platforms you want to build
  5. And here we go Build -> Build Solution, which should produce binaries in the bin dir

Following these steps and building all binaries in their Release versions took me ~2 minutes on my laptop.

Download prebuilt binaries

Try to look for them here

Update to the latest version of SQLite

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:

1. Automatic

  • Run premake update or tools\update.bat

*Requires PowerShell

2. Manual

  1. Download the source code of the latest release of wxsqlite3
  2. Extract the wxsqlite3-*/sqlite3/secure/src dir from the archive to src dir in the project root dir.

Notes

  • VERSIONS file in the repo root dir keeps an overview of versions of individual components provided in the repo

Alternatives

There 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.

SQLite3 Encryption API

Functions

#define SQLITE_HAS_CODEC
#include <sqlite3.h>

sqlite3_key, sqlite3_key_v2

Set the key for use with the database

  • This routine should be called right after sqlite3_open.
  • The 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 */
);

Testing the key

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;

sqlite3_rekey, sqlite3_rekey_v2

Change the encryption key for a database

  • If the current database is not encrypted, this routine will encrypt it.
  • If pKey==0 or nKey==0, the database is decrypted.
  • The 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 */
);

PRAGMAs

PRAGMA key

  • it's wrapper around sqlite3_key_v2
  • example usage: PRAGMA key='passphrase';

PRAGMA rekey

  • it's wrapper around sqlite3_rekey_v2
  • example usage: PRAGMA rekey='passphrase';
  • example of decrypting: PRAGMA rekey='';

Tutorials

Encrypting a new db

open          // <-- db is still plain text
key           // <-- db is now fully encrypted
use as usual

Opening an encrypted DB

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

Changing the key

open          // <-- db is fully encrypted
key           // <-- db is still fully encrypted
rekey         // <-- db is still fully encrypted
use as usual  

Decrypting

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

Read more

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].