问题
I'm just learning how to encrypt/decrypt SQLite database.
I found a way to encrypt, as in this post SQLite with encryption/password protection
This page's best answer said that we can use SEE
,wxSQLite
,SQLCipher
,SQLiteCrypt
, etc... to encrypt.
I can understand.
And, another answer said that we can use:
SQLiteConnection conn = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
conn.SetPassword("password");
conn.open();
This page also says the same: Password Protect a SQLite DB. Is it possible?
However, SQLiteConnection
doesn't have SetPassword
nor ChangePassword
methods.
I'm very confused.
Where are SetPasword
or ChangePassword
?
Are these in SEE
, wxSQLite
,SQLCipher
,SQLiteCrypt
?
[Development environment]
VisualStudio2010 .NET Framework 4 Client Profile System.Data.SQLite.dll (https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki)
I downloaded zip from there, and I picked up "System.Data.SQLite.dll"
回答1:
SQLite no longer has "SetPassword" or "ChangePassword".
To initially set the password you use the following:
var connectionString = new SqliteConnectionStringBuilder(baseConnectionString)
{
Mode = SqliteOpenMode.ReadWriteCreate,
Password = password
}.ToString();
To change the password you would do the following:
var command = connection.CreateCommand();
command.CommandText = "SELECT quote($newPassword);";
command.Parameters.AddWithValue("$newPassword", newPassword);
var quotedNewPassword = (string)command.ExecuteScalar();
command.CommandText = "PRAGMA rekey = " + quotedNewPassword;
command.Parameters.Clear();
command.ExecuteNonQuery();
来源:https://stackoverflow.com/questions/62294577/where-is-setpassword-or-changepassword-in-sqliteconnection-class