Sunday, 10 April 2016

c# - 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?


Answer



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!



No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...