我刚刚学习如何加密/解密 SQLite 数据库。
我找到了一种加密方法,如这篇文章《具有加密/密码保护的 SQLite》
本页的最佳答案说我们可以使用SEE、wxSQLite、SQLCipher、SQLiteCrypt等...来加密。
我能够了解。
而且,另一个答案说我们可以使用:
SQLiteConnection conn = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
conn.SetPassword("password");
conn.open();
Run Code Online (Sandbox Code Playgroud)
此页面也说了同样的话: 密码保护 SQLite DB。是否可以?
然而,SQLiteConnection没有SetPassword也没有ChangePassword方法。我很困惑。
SetPasword或在哪里ChangePassword?这些
是在SEE、、、wxSQLite吗SQLCipher?SQLiteCrypt
[开发环境]
VisualStudio2010 .NET Framework 4 Client Profile System.Data.SQLite.dll ( https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki )
我从那里下载了 zip,然后选择了“System.Data.SQLite.dll”
小智 -1
SQLite 不再具有“SetPassword”或“ChangePassword”。
要初始设置密码,请使用以下命令:
var connectionString = new SqliteConnectionStringBuilder(baseConnectionString)
{
Mode = SqliteOpenMode.ReadWriteCreate,
Password = password
}.ToString();
Run Code Online (Sandbox Code Playgroud)
要更改密码,您需要执行以下操作:
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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7522 次 |
| 最近记录: |