sequelize / website

Our beloved website that contains all versions of our documentations and the API references.
https://sequelize.org
29 stars 152 forks source link

Sequelize using SQLcipher to encrypt DB #729

Open juancampuzano opened 4 years ago

juancampuzano commented 4 years ago

Issue Description

I am trying to encrypt the database using SQLCipher. In the Sequelize documentation it says that it is possible to do: "Supports SQLCipher encryption for SQLite." But in the documentation I can't find the steps of how to do. I am trying to follow the following example found in Stackoverflow but I get the error: "SQLITE_NOTAD"

StackOverflow / Slack attempts

related case: https://stackoverflow.com/questions/33363075/how-to-make-encrypted-sqlite3-database-with-nodejs-in-windows-platform

Is this issue dialect-specific?

Would you be willing to resolve this issue by submitting a Pull Request?

papb commented 4 years ago

Hello, can you please try a few things:

Let me know, thanks

juancampuzano commented 4 years ago

I was testing with version v4.0.0-1 but I had the same problem.

However, I have the following question: is it possible to encrypt the database using sequelize in other way?

How can I run the following command PRAGMA key = 'mysecret' when starting sequelize?

papb commented 4 years ago

I am not familiar with database encryption unfortunately. I would suggest you try a direct raw query as early as possible in your code: sequelize.query("PRAGMA key = 'mysecret'") but I don't know if it should work.

juancampuzano commented 4 years ago

@papb it works.

Base on node-sqlcipher, I only have to put the following code:

  const sequelize = new Sequelize('database', '', 'your-encryption-key' {
    dialect: 'sqlite',
    dialectModulePath: '@journeyapps/sqlcipher',
    storage:  'path/to/db.sqlite',
  });

  // SQLCipher config
  sequelize.query('PRAGMA cipher_compatibility = 3');
  sequelize.query("PRAGMA key = 'your-encryption-key'");
papb commented 4 years ago

Fantastic!! I will leave it open as a docs issue :grimacing:

juancampuzano commented 4 years ago

Do you create the documentation?

rohit5ram commented 4 years ago

@juancampuzano @papb How can we default it to use sqlcipher 4 without cipher_compatibility? I have opened an issue in node-sqlcipher too https://github.com/journeyapps/node-sqlcipher/issues/33

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂