how to set password for sqllite database?


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:

staticint sqlite3_open( //same syntax for sqlite3_open16

constchar *zFilename, // IN: Database filename UTF-8 encoded

const char *strPass, //IN: Pass Phrase

sqlite3 **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

constchar* 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
SQLite version 3.3.8
Enter “.help” for instructions
sqlite> create table Test(a INT, b INT);
sqlite> insert into Test values(327, 86);
sqlite> select * from Test;
327|86
sqlite> .changepass 12345678
sqlite> select * from Test;
327|86
sqlite> .exit

Example 2: Create encrypted database

D:\>sqlite.exe 12345678 test.db
SQLite version 3.3.8
Enter “.help” for instructions
sqlite> create table Test(a INT, b INT);
sqlite> insert into Test values(327, 86);
sqlite> select * from Test;
327|86
sqlite> .exit

Example 3: Open encrypted database using wrong pass phrase

Supply wrong pass phrase:

D:\>sqlite.exe pass test.db
Unable to open database “test.db”: supplied password is incorrect

No pass phrase supplied:

D:\>sqlite.exe test.db
SQLite version 3.3.8
Enter “.help” for instructions
sqlite> select * from Test;
SQL error: database disk image is malformed
sqlite> .exit

Example 4: Open encrypted database query, then make it regular SQLite database (remove encryption)

D:\>sqlite.exe 12345678 test.db
SQLite version 3.3.8
Enter “.help” for instructions
sqlite> select * from Test;
327|86
sqlite> .changepass
sqlite> select * from Test;
327|86
sqlite> .exit

Example 5: Open encrypted database, make queries, then change pass phrase

D:\>sqlite.exe 12345678 test.db
SQLite version 3.3.8
Enter “.help” for instructions
sqlite> select * from Test;
327|86
sqlite> .changepass 87654321
sqlite> select * from Test;
327|86
sqlite> .exit

D:\>sqlite.exe 87654321 test.db
SQLite version 3.3.8
Enter “.help” for instructions
sqlite> select * from Test;
327|86
sqlite> .exit

Refer by: http://sqlite-crypt.com/documentation.htm

About these ads

About aravindmcse

I am aravinda kumar my native is komarapalayam, it located at nearest of erode.now I working in Chennai as software engineer

Posted on June 25, 2011, in Uncategorized. Bookmark the permalink. 2 Comments.

  1. Hai Aravind

    Thank U for this service

  2. Hai Aravind

    How to connect ASP.net with sql Database using three tier architecture?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: