Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i password encrypt SQLite database?

I am using SQLite database version 3 with C# Windows application.. i want to encrypt the SQLite database file using password or any other encryption way in order to prevent clients to open it from program files folder.

i don't want any runtime encryption ways, i just want to make the database file show password field when a client try to open it from the program files .. thanks

Edit

and if i encrypted it from code,the client can open it when the installation complete and db file transferred to the program files before opening the program to perform the encryption isnt it?

like image 877
Hassanation Avatar asked Aug 30 '12 05:08

Hassanation


2 Answers

I use SQLite version 3 works perfectly! You have to do that:

//if the database has already password
try{
            string conn = @"Data Source=database.s3db;Password=Mypass;";
            SQLiteConnection connection= new SQLiteConnection(conn);
            connection.Open();
            //Some code
            connection.ChangePassword("Mypass");
            connection.Close();
    }
//if it is the first time sets the password in the database
catch
    {
            string conn = @"Data Source=database.s3db;";
            SQLiteConnection connection= new SQLiteConnection(conn);
            connection.Open();
            //Some code
            connection.ChangePassword("Mypass");
            connection.Close();
    }

thereafter if the user tries to open the database. will say protected by Admin or the database is encrypted or is not a database or corrupted file!

like image 62
Luis Granado Avatar answered Oct 11 '22 20:10

Luis Granado


Found in this forum an post indicating that ..

Standard SQLite3 API doesn't offer any form of protection and relies only on underlying OS privileges mecanism (if any) for "security". If you have an existing SQLite-style database which uses a specific API to gain access, then you should use this particular (non-standard) API.

If you can/want to use some kind of extension for SQLite you can also try SQLite Encryption Extension (SEE) or SQLite Crypt

But you can change/set a password for your database using SQLite.Data as shown in this article.

like image 24
Pilgerstorfer Franz Avatar answered Oct 11 '22 19:10

Pilgerstorfer Franz