You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法在DB Browser for SQLite中打开SQLCipher加密的SQLite数据库

问题:SQLCipher加密的SQLite数据库无法在DB Browser for SQLite中打开

开发一个使用SQLCipher加密SQLite数据库的C#应用,应用内使用正确密码可正常加密并访问数据库,但尝试在DB Browser for SQLite中打开时失败,输入正确密码后收到错误提示:Incorrect key used to decrypt the database。

已执行步骤

  • 在C#中使用SQLCipher加密SQLite数据库
  • 尝试在DB Browser for SQLite中打开该加密数据库
  • 输入正确密码尝试解密

相关代码

string distFileName = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop), "dbTest1.db");

string password = "1234";

SQLiteConnection.CreateFile(distFileName);

SQLiteConnection connection = new SQLiteConnection($"Data Source={distFileName};Version=3;");

connection.SetPassword("1234");
connection.Open();

// Create a table
using (SQLiteCommand createTableCmd = new SQLiteCommand(
           "CREATE TABLE IF NOT EXISTS MyTable (Id INTEGER PRIMARY KEY, Name TEXT, Age INTEGER);",
           connection))
{
    createTableCmd.ExecuteNonQuery();
}

connection.Close();

SQLiteConnection connectionInsert =
        new SQLiteConnection($"Data Source={distFileName};Version=3;password={password};");
connectionInsert.Open();

// Insert data into the table
using (SQLiteCommand insertDataCmd = new SQLiteCommand(
           "INSERT INTO MyTable (Name, Age) VALUES ('Alice', 30), ('Bob', 25), ('Charlie', 35);",
           connectionInsert))
{
    insertDataCmd.ExecuteNonQuery();
}

connectionInsert.Close();

SQLiteConnection connectionRead =
        new SQLiteConnection($"Data Source={distFileName};Version=3;password={password};");

connectionRead.Open();
// Read the data from the table
using (SQLiteCommand selectDataCmd = new SQLiteCommand("SELECT * FROM MyTable", connectionRead))
{
    using (SQLiteDataReader reader = selectDataCmd.ExecuteReader())
    {
        while (reader.Read())
        {
            int id = Convert.ToInt32(reader["Id"]);
            string name = reader["Name"].ToString();
            int age = Convert.ToInt32(reader["Age"]);

            Console.WriteLine($"Id: {id}, Name: {name}, Age: {age}");
        }
    }
}

connection.Close();
}
catch (Exception ex)
{
    Debug.WriteLine($"Error: {ex.Message}");
    // Handle the exception, log it, or display an error message to the user.
}
}

预期与实际行为

预期行为:可使用正确密码在DB Browser for SQLite中打开该加密SQLite数据库。
实际行为:无法打开加密数据库,收到Incorrect key used to decrypt the database错误提示。

已尝试的解决方法

  • 反复核对加密所用密码,确认输入正确
  • 尝试使用其他SQLite浏览器打开,均失败

涉及版本

  • SQLCipher版本:4.4.3
  • DB Browser for SQLite版本:3.12.0
  • C# .NET版本:4.7.2

内容的提问来源于stack exchange,提问作者sw01

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 09:35:09