![]() |
Home | Purchase | Contact Us |
|
|
|
|
SQLiteCrypt API SQLiteCrypt is very easy to use. SQLiteCrypt is based on SQLite, so most API functions remain unchanged. Please refer to SQLite documenttation. SQLiteCrypt modifies only one SQLite function: static int sqlite3_open( //same syntax for sqlite3_open16const char *zFilename, // IN: Database filename UTF-8 encoded const char *strPass, //IN: Pass Phrasesqlite3 **ppDb /* OUT: Returned database handle */ )New openDatabase method has 3 parameters, instead of 2 in original SQLite openDatabase. New parameter is pass-phrase. Only added function in SQLiteCrypt is sqlite3_changepassword: void sqlite3_changepassword(sqlite3* db, //IN: Database handle const char* strNewPass/*IN: New pass phrase, up to 128 characters*/) Remark: Do not call sqlite3_changepassword function in middle of transaction, or when database is not committed (if auto commit turned off). This method decrypt whole database using old pass phrase, then encrypt using new pass phrase. You can continue to use SQLite API functions, no need of closing and re-opening database. sqlite3_changepassword is time-consuming operation. Example 1: Encrypt SQLite database sqlite3 *pDb; int rc = openDatabase(zFilename, "", &pDb); //Open regular (non-encrypted) SQLite database//execute SQL commands here, but finish all transactions and commit before call sqlite3_changepassword sqlite3_changepassword(pDb, "new pass phrase"); //encrypt database //execute SQL commands here Example 2: Decrypt SQLite database (remove encryption, so any other SQLite application can open it) sqlite3 *pDb; int rc = openDatabase(zFilename, "pass phrase", &pDb); //Open encrypted SQLite database//execute SQL commands here, but finish all transactions and commit before call sqlite3_changepassword sqlite3_changepassword(pDb, ""); //decrypt database by supplying empty pass phrase //execute SQL commands here Example 3: Change encryption key on-the-fly sqlite3 *pDb; int rc = openDatabase(zFilename, "pass phrase", &pDb); //Open encrypted SQLite database//execute SQL commands here, but finish all transactions and commit before call sqlite3_changepassword sqlite3_changepassword(pDb, "new pass phrase"); //change encryption key by supplying new pass phrase //execute SQL commands here SQLiteCrypt command line tool Download SQLiteCrypt command line tool here. SQLiteCrypt command line tool source code is here. You can compare with original command line tool source code available in SQLite distribution. Using SQLiteCrypt command line tool: Example 1: Create new regular SQLite database, then encrypt it D:\>sqlite.exe test.db Example 2: Create encrypted database D:\>sqlite.exe
12345678 test.db Example 3: Open encrypted database using wrong pass phrase Supply wrong pass phrase: D:\>sqlite.exe pass
test.db No pass phrase supplied: D:\>sqlite.exe test.db Example 4: Open encrypted database query, then make it regular SQLite database (remove encryption) D:\>sqlite.exe
12345678 test.db Example 5: Open encrypted database, make queries, then change pass phrase D:\>sqlite.exe
12345678 test.db
|
||||||||||||||||||||||||||||
|
Copyright © SQLiteCrypt |
|||||||||||||||||||||||||||||