本文介绍了"SetPassword"在哪里?或"ChangePassword"在SQLiteConnection类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何加密/解密SQLite数据库.
我找到了一种加密方法,如本文中具有加密/密码保护的SQLite

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

此页的最佳答案表示我们可以使用 SEE wxSQLite SQLCipher SQLiteCrypt 等...进行加密.

This page's best answer said that we can use SEE,wxSQLite,SQLCipher,SQLiteCrypt, etc... to encrypt.

我能理解.

然后,另一个答案说我们可以使用:

And, another answer said that we can use:

SQLiteConnection conn = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
conn.SetPassword("password");
conn.open();

此页面也显示相同的内容:密码保护SQLite数据库.有可能吗?

This page also says the same:Password Protect a SQLite DB. Is it possible?

但是, SQLiteConnection 没有 SetPassword ChangePassword 方法.我很困惑

However, SQLiteConnection doesn't have SetPassword nor ChangePassword methods. I'm very confused.

SetPasword ChangePassword 在哪里?
这些是在 SEE wxSQLite SQLCipher SQLiteCrypt 中吗?

Where are SetPasword or ChangePassword?
Are these in SEE, wxSQLite,SQLCipher,SQLiteCrypt?

我从那里下载了zip,然后选择了"System.Data.SQLite.dll"

I downloaded zip from there, and I picked up "System.Data.SQLite.dll"

推荐答案

SQLite不再具有"SetPassword"或"ChangePassword".

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();

这篇关于"SetPassword"在哪里?或"ChangePassword"在SQLiteConnection类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 19:24