Shajiye Mir
Shajiye Mir

Reputation: 11

How to decrypt/open (.db) SQLite database file

How to open a file with the .db extension of SQLite database?

I have downloaded a DB Browser For SQLite. When I tried opening the database file, a new window popped up which is 'Titled SQLCipher Encryption' asking a password used to encrypt and file size (Confused With What Exactly 'File Size'..?).

I have an Application Source Code that I Managed To Find Password & tried with default Page Size 1024.

Tried Several times but unable to open.

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

In namespace,

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;

Upvotes: -1

Views: 9841

Answers (1)

Michal Kandel
Michal Kandel

Reputation: 323

1. regarding your question about page size, please refer to SQLite Database file Format

1.3.2. Page Size The two-byte value beginning at offset 16 determines the page size of the database. For SQLite versions 3.7.0.1 (2010-08-04) and earlier, this value is interpreted as a big-endian integer and must be a power of two between 512 and 32768, inclusive. Beginning with SQLite version 3.7.1 (2010-08-23), a page size of 65536 bytes is supported. The value 65536 will not fit in a two-byte integer, so to specify a 65536-byte page size, the value at offset 16 is 0x00 0x01. This value can be interpreted as a big-endian 1 and thought of as a magic number to represent the 65536 page size. Or one can view the two-byte field as a little endian number and say that it represents the page size divided by 256. These two interpretations of the page-size field are equivalent.

You can check the size of the database by using the ".dbinfo" command in an ordinary sqlite3.exe command-line shell program. The first info is the size

database page size:  4096

2. Regarding db decryption Assuming the db is encrypted and you have the right passwords, (does it start with x' or 0x?, have you managed to open the db manually using the DB Browser app?), you'll have to decrypt the db before being able to read it. please refer SQLite Encryption Extension Documentation in order to learn more about the SQLite encryptions (& decryptions).

I suggest to use some opened source written cipher. just google it up and see which one is comfortable for you to work with. here's an example cipher that might be good for your needs

Upvotes: 1

Related Questions