m4heshd / better-sqlite3-multiple-ciphers

better-sqlite3 with multiple-cipher encryption support 🔒
MIT License
140 stars 27 forks source link

SQLCipher decrypte Error #25

Closed binvb closed 2 years ago

binvb commented 2 years ago

i was using better-sqlite3-multiple-ciphers in electron project, it was fine in application. here's my config in typeorm:

    name,
    type:'better-sqlite3',
    driver: require('better-sqlite3-multiple-ciphers'),
    synchronize: _synchronize,
    key: 'secret-key',
    logging: ["error"],
    logger: true,  
    verbose: console.log,
    database: path.join(app.getPath('userData'), `./db/user.sqlite`),
    entities: [
      path.join(app.getAppPath(), './src/entity/*.ts')
    ],
    prepareDatabase: db => {
      db.pragma(`legacy=3`)
    }   

but when i was try to use SQLCipher to decrypte user.sqlite database file, i turn's error:

sqlcipher user.sqlite
SQLite version 3.36.0 2021-06-18 18:36:39 (SQLCipher 4.5.0 community)
Enter ".help" for usage hints.
sqlite> PRAGMA key='secret-key';
ok
sqlite> PRAGMA cipher_compatibility = 3;;
sqlite> ATTACH DATABASE 'decrypted_user.sqlite' AS user KEY '';
Error: file is not a database

it's any solution for decrypte database file outside application? thank you guys

m4heshd commented 2 years ago

It's bit tricky when it comes to SQLCipher because of the multiple modes.

Can you try a DB created with legacy=4 PRAGMA? Take a look at issue #14.

binvb commented 2 years ago

It's bit tricky when it comes to SQLCipher because of the multiple modes.

Can you try a DB created with legacy=4 PRAGMA? Take a look at issue #14.

thank you so much, it help me a lot