Where is “SetPassword” or “ChangePassword” in SQLiteConnection class?

若如初见. 提交于 2020-08-09 09:13:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!