journeyapps / node-sqlcipher

SQLCipher bindings for Node
https://journeyapps.com
BSD 3-Clause "New" or "Revised" License
207 stars 66 forks source link

How can I default to sqlcipher4 with sequelize? #33

Open rohit5ram opened 4 years ago

rohit5ram commented 4 years ago
const Sequelize = require("sequelize");
const db = new Sequelize({
    dialect: 'sqlite',
    storage: path.join(process.cwd(), "sample.db"),
    dialectModulePath: '@journeyapps/sqlcipher',
    logging: false,
    define: {
        freezeTableName: true
    }
});
db.query("PRAGMA key = 'password'");

I am not able to open the sample.db file with sqlitebrowser SQLCIPHER 4. Screenshot from 2020-04-16 11-57-50

The only way its works is by adding the below line and then use SQLICIPHER 3 in sqlitebrowser db.query('PRAGMA cipher_compatibility = 3'); Screenshot from 2020-04-16 11-58-50

rkistner commented 4 years ago

Which version of this package are you using?

The SQLCipher 4 defaults should be used by default, so I'm not sure why this isn't working.

You can try to set the individual parameters explicitly to match sqlitebrowser:

PRAGMA cipher_page_size = 4096;
PRAGMA kdf_iter = 256000;
PRAGMA cipher_hmac_algorithm = HMAC_SHA512;
PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA512;
rohit5ram commented 4 years ago

@rkistner I use @journeyapps/sqlcipher": "^4.1.0

rkistner commented 4 years ago

I've tested with @journeyapps/sqlcipher versions 4.1.0 and 5.0.0, and couldn't reproduce in either version.

Tested with sqlitebrowser 3.12.99 / sqlcipher 4.3.0.

If you still run into the issue, I recommend:

  1. Test with the sqlcipher CLI instead of sqlitebrowser.
  2. Test using this library directly, without sequelize.

Also check whether adding PRAGMA cipher_compatibility = 4 (before setting the key) makes a difference.