【问题标题】:How to decrypt/open (.db) SQLite database file如何解密/打开(.db)SQLite 数据库文件
【发布时间】:2017-02-20 22:41:48
【问题描述】:

如何打开 SQLite 数据库扩展名为 .db 的文件?

我已经下载了 SQLite 的数据库浏览器。 当我尝试打开数据库文件时,弹出一个名为“标题为 SQLCipher Encryption”的新窗口,询问用于加密的密码和文件大小(与究竟是什么“文件大小”混淆......?)。

我有一个应用程序源代码,我设法找到密码并尝试使用默认页面大小 1024。

试了好几次都打不开。

  public void ReadRecord(string sql)
    {
        try
        {
            this.sqlite_cmd.CommandText = this.cSql;
            this.sqlite_datareader = this.sqlite_cmd.ExecuteReader();
            if (this.sqlite_datareader.Read())
            {
                this.sAddEdit = "E";
                this.txt1.Tag = this.sqlite_datareader["id"];
                this.txt1.Text = this.sqlite_datareader["f0"].ToString();
                this.txt2.Text = this.sqlite_datareader["f1"].ToString();
                this.txt3.Text = this.sqlite_datareader["f2"].ToString();
                this.txt4.Text = this.sqlite_datareader["f3"].ToString();
                this.txt5.Text = this.sqlite_datareader["f4"].ToString();
                this.dtpListDate.Text = this.sqlite_datareader["f5"].ToString();
                this.txt7.Text = this.sqlite_datareader["f6"].ToString();
                this.txt8.Text = this.sqlite_datareader["f7"].ToString();
                this.txt9.Text = this.sqlite_datareader["f8"].ToString();
                this.txt10.Text = this.sqlite_datareader["f9"].ToString();
                this.txt11.Text = this.sqlite_datareader["f10"].ToString();
                this.txt12.Text = this.sqlite_datareader["f11"].ToString();
                this.txt13.Text = this.sqlite_datareader["f12"].ToString();
                this.txt14.Text = this.sqlite_datareader["f13"].ToString();
                this.txt15.Text = this.sqlite_datareader["f14"].ToString();
                this.txt16.Text = this.sqlite_datareader["f15"].ToString();
                this.txt17.Text = this.sqlite_datareader["f16"].ToString();
                this.txt18.Text = this.sqlite_datareader["f17"].ToString();
                this.txt19.Text = this.sqlite_datareader["f18"].ToString();
                this.txt20.Text = this.sqlite_datareader["f19"].ToString();
                this.txt21.Text = this.sqlite_datareader["f20"].ToString();
                this.txt22.Text = this.sqlite_datareader["f21"].ToString();
                this.txt23.Text = this.sqlite_datareader["f22"].ToString();
                this.txt24.Text = this.sqlite_datareader["f23"].ToString();
                this.txt25.Text = this.sqlite_datareader["f24"].ToString();
                this.txt26.Text = this.sqlite_datareader["f25"].ToString();
                this.txt27.Text = this.sqlite_datareader["f26"].ToString();
                this.txt28.Text = this.sqlite_datareader["f27"].ToString();
                this.txt29.Text = this.sqlite_datareader["f28"].ToString();
                this.txt30.Text = this.sqlite_datareader["f29"].ToString();
            }
            this.sqlite_datareader.Close();
        }
        catch (Exception exception)
        {
            MessageBox.Show("A Error" + exception.ToString() + " Occcured Please Try Again or contact supplier", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
        }
    }

在命名空间中,

using Microsoft.VisualBasic.PowerPacks;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

【问题讨论】:

  • 嘿,@ArtjomB。仅供参考,我已共享代码
  • 欢迎使用 stackoverflow。你想用 FillHeader() 做什么; ?而且似乎缺少 SqlCommand 的语法..
  • 谢谢@KayLee 我只想打开文件并检查我的工作:我已经替换了 FillHeader();带有代码的东西包含 SqlCommand
  • 我的代码只是确认连接是否打开。但是,为了读取数据库中的内容,您需要了解数据库的结构,例如表名、列名、数据类型。否则,您必须使用 DB Browser 或 Server Management Studio。它是免费且可下载的。
  • 像这样的整个try/catch (Exception) 是一个糟糕的反模式。阅读Eric Lippert's Vexing Exceptions

标签: c# sqlite encryption connection


【解决方案1】:

1.关于您关于页面大小的问题, 请参考SQLite Database file Format

1.3.2。页面大小 从偏移量 16 开始的两字节值决定了数据库的页面大小。对于 SQLite 版本 3.7.0.1 (2010-08-04) 及更早版本,此值被解释为大端整数,并且必须是 512 和 32768 之间(含)的 2 的幂。从 SQLite 版本 3.7.1 (2010-08-23) 开始,支持 65536 字节的页面大小。值 65536 不适合两个字节的整数,因此要指定 65536 字节的页面大小,偏移量 16 处的值是 0x00 0x01。该值可以解释为大端序 1,并被认为是代表 65536 页面大小的幻数。或者可以将两字节字段视为一个小端序数,并说它表示页面大小除以 256。这两种对页面大小字段的解释是等价的。

您可以在普通的 sqlite3.exe 命令行 shell 程序中使用“.dbinfo”命令来检查数据库的大小。第一个信息是大小

database page size:  4096

2。关于数据库解密 假设数据库已加密并且您拥有正确的密码(它是以 x' 还是 0x 开头?您是否设法使用 DB Browser 应用程序手动打开数据库?),您必须先解密数据库才能能够阅读它。请参考SQLite Encryption Extension Documentation 以了解有关 SQLite 加密(和解密)的更多信息。

我建议使用一些开源的书面密码。只需 google 一下,看看哪一个对你来说很舒服。 here's an example cipher that might be good for your needs

【讨论】:

    猜你喜欢
    • 2022-10-08
    • 2016-03-02
    • 2014-11-11
    • 2014-08-30
    • 1970-01-01
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多