Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The password issuses by opening Sqlite.db files by sqlitebrowser or sqlite-net #1260

Open
BoydenYubin opened this issue Nov 25, 2024 · 0 comments

Comments

@BoydenYubin
Copy link

(1)Encrypt the db file by using the sqlitebrowser

I have checked the logic of sqlitebrowser to encrypt the db file as below.

db.executeSQL("ATTACH DATABASE 'temp.db' AS sqlitebrowser_edit_encryption KEY 'password';");
db.executeSQL("PRAGMA sqlitebrowser_edit_encryption.cipher_page_size = 1024");
db.executeSQL("PRAGMA sqlitebrowser_edit_encryption.cipher_hmac_algorithm = HMAC_SHA1;"; 
db.executeSQL("PRAGMA sqlitebrowser_edit_encryption.cipher_kdf_algorithm = PBKDF2_HMAC_SHA1;");
db.executeSQL("PRAGMA sqlitebrowser_edit_encryption.kdf_iter = 64000;");
db.executeSQL("PRAGMA sqlitebrowser_edit_encryption.cipher_plaintext_header_size = 0;");
db.executeSQL("SELECT sqlcipher_export('sqlitebrowser_edit_encryption');");
db.executeSQL("DETACH sqlitebrowser_edit_encryption;");

This object db is encrypted by sqlitebrowser with password password, and every time it was open by above steps the temp db file will be built ans then exchage the file. You could check the original link as sqlitebrowser check link 3341.

(2)Decrypt the db file by using the sqlite-net

When I try to use above steps to open the db files by using sqlite-net, it will show not an error. By the way, I used the sqlitecipher instead of standard sqlite.dll. And realize the sqlitecipher API as API defination.

var options = new SQLiteConnectionString(databasePath: "test.db", 
    storeDateTimeAsTicks:true, 
    openFlags: SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create,
    preKeyAction: db =>
    {
        //db.Execute("PRAGMA key = 'password';"); // it can't be excuted
        db.Key("admin");
        db.Execute($"ATTACH DATABASE '{tempfile}' AS sqlitebrowser_edit_encryption KEY 'password';"); //display 'not an error'
        db.Execute("PRAGMA sqlitebrowser_edit_encryption.cipher_plaintext_header_size = 0;");
        db.Execute("PRAGMA sqlitebrowser_edit_encryption.cipher_page_size = 1024;");
        db.Execute("PRAGMA sqlitebrowser_edit_encryption.cipher_kdf_algorithm = PBKDF2_HMAC_SHA1;");   //;
        db.Execute("PRAGMA sqlitebrowser_edit_encryption.kdf_iter = '64000';");
        db.Execute("PRAGMA sqlitebrowser_edit_encryption.cipher_default_hmac_algorithm = HMAC_SHA1;");
        db.Execute("SELECT sqlcipher_export('sqlitebrowser_edit_encryption');");
        db.Execute("DETACH sqlitebrowser_edit_encryption;");
    }
    );
var encryptedDb = new SQLiteConnection(options);
// next step the exexute  sql

(3)Decrypt the db file by using the sqlcipher

And I have tried the sqlciper way on Ubuntu, it works if we used above steps.
image

So any other mistake sqlite-net deal with the pre-action? Thanks for your feedback if no bother.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant