My SQLite databases are encrypted at build time.
Small tools were developed to remove or apply the password to all 9 databases
after build to facilitate the work of the database developers. The tools run
the following bit of code against each database:
string activatePragma = "PRAGMA activate_extensions='SEE Code';";
string passwordPragma = "PRAGMA key='" + password + "';";
SQLiteConnection connection = new SQLiteConnection("Data Source = " +
databaseFile);
connection.Open();
if (applyPassword)
{
using (SQLiteCommand pragmaCommand = new SQLiteCommand(connection))
{
pragmaCommand.CommandText = activatePragma;
pragmaCommand.ExecuteNonQuery();
}
connection.ChangePassword(password);
}
else
{
using (SQLiteCommand pragmaCommand = new SQLiteCommand(connection))
{
pragmaCommand.CommandText = activatePragma;
pragmaCommand.ExecuteNonQuery();
pragmaCommand.CommandText = passwordPragma;
pragmaCommand.ExecuteNonQuery();
}
connection.ChangePassword("");
}
connection.Close();
Starting with an encrypted database, if I run this code twice in a row with
applyPassword=false, the password is removed the first time but then applied
the second time.
Similarly, starting with an unencrypted database, fi I run this code twice in a
row with applyPassword=true, the password is applied the first time but then
removed the second time.
I can kind of see where perhaps when running the removal the second time, the
"PRAGMA key=" bit is actually now applying the password.
But I don't understand why executing ChangePassword twice in a row on an
unencrypted database would remove the password the second time.
Take care,
Melody R Baugher
DCS Corporation
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users