1

I set an encryption key for my database in DB Browser for SQLite and now I cannot access it in C#.

Here's the relevant code:

    private SQLiteConnection connection;

    public DbManager()
    {
        connection = new SQLiteConnection("Data Source=DB\\gamedb.encrypted.sqlite;Password=p4ssw0rd;Version=3;");
        connection.Open();
    }

The SQLiteCommand below throws an exception: "file is encrypted or is not a database".

    public Dictionary<string, string> ReadMaps()
    {
        SQLiteDataReader reader = new SQLiteCommand("select * from Map", connection).ExecuteReader();
        Dictionary<string, string> res = new Dictionary<string, string>();
        while (reader.Read())
            res[(string)reader["Name"]] = (string)reader["Data"];
        return res;
    }

Is the key specified in the DB browser a different thing than a password?

5
  • Did you in fact encrypt it at some point? Using a PW on an unencrypted DB File will fail the same as a wrong PW Commented Oct 15, 2016 at 15:55
  • I'm not sure, I thought setting the encryption key would have encrypted the file Commented Oct 15, 2016 at 16:00
  • Where do you do that with DBBrowser? I have never found where to tell it anything about the encryption PW Commented Oct 15, 2016 at 16:01
  • File -> Set Encryption Commented Oct 15, 2016 at 18:27
  • 2
    That is apparently brand new in the latest version. I cant get it to work right either. It does encrypt the DB when you first set it, and it can read it, but I cant get a NET app to read that db with the PW. The reverse is true - if I apply the PW from code, my code can use the DB, but not DB Browser. If you look at the bug list there are several issues regarding this. It is using a different method than the NET provider apparently Commented Oct 15, 2016 at 19:01

1 Answer 1

1

I decided to handle setting the password by coding, it works. I created a new project for setting/clearing the password.

Here's the code:

    SQLiteConnection conn;

    // (code omitted)

    private void setPwButton_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(passwordTextBox.Text))
            conn.ChangePassword(passwordTextBox.Text);
        else
            MessageBox.Show("Please specify a password!");
    }

    private void clearPwButton_Click(object sender, EventArgs e)
    {
        conn.ChangePassword(String.Empty);
    }
Sign up to request clarification or add additional context in comments.

2 Comments

I am having the same issue. The problem is that System.Data.SQLite uses a different encryption and "DB Browser for SQLite" uses the Cipher encryption. After encrypting the DB using conn.ChangePassword(passwordTextBox.Text); can you open it with "DB Browser for SQLite"?
I have very similar issues. If I create an encrypted/password protected sqlite db using a .NET app using the library System.Data.SQLite I can ONLY access the data using my own app and I am unable to open it using SQLiteStudio 3.2.1. However if I create the db file using SQLiteStudio I can then access that db and the data using my .NET app by supplying the password. I would really like to be able to create the db in my .NET app and then be able to supply that same password to access that same DB from within SQLiteStudio.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.