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

Sequelize using SQLcipher to encrypt DB #729

Open
2 of 7 tasks
juancampuzano opened this issue Oct 24, 2019 · 8 comments
Open
2 of 7 tasks

Sequelize using SQLcipher to encrypt DB #729

juancampuzano opened this issue Oct 24, 2019 · 8 comments

Comments

@juancampuzano
Copy link

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?

  • No. This issue is relevant to Sequelize as a whole.
  • Yes. This issue only applies to the following dialect(s): SQLCipher on Sequelize
  • I don't know.

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

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
@papb
Copy link
Member

papb commented Oct 24, 2019

Hello, can you please try a few things:

  • Try with the first version of sequelize that had support for this feature (in this case, v4.0.0-1)

  • See if you can do it without sequelize using the sqlite3 package directly

  • Try to create a sequelize-sscce for it considering that I have no idea how SQLCipher works (so try to make it 100% ready for test)

Let me know, thanks

@juancampuzano
Copy link
Author

juancampuzano commented Oct 24, 2019

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
Copy link
Member

papb commented Oct 25, 2019

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
Copy link
Author

juancampuzano commented Oct 25, 2019

@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
Copy link
Member

papb commented Oct 25, 2019

Fantastic!! I will leave it open as a docs issue 😬

@papb papb reopened this Oct 25, 2019
@papb papb self-assigned this Oct 25, 2019
@juancampuzano
Copy link
Author

Do you create the documentation?

@rohit5ram
Copy link

rohit5ram commented Apr 16, 2020

@juancampuzano @papb How can we default it to use sqlcipher 4 without cipher_compatibility?
I have opened an issue in node-sqlcipher too
journeyapps/node-sqlcipher#33

@github-actions
Copy link

github-actions bot commented Nov 6, 2021

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. 🙂

@github-actions github-actions bot added the stale label Nov 6, 2021
@WikiRik WikiRik removed the stale label Nov 15, 2021
@ephys ephys removed the status: wip label Mar 27, 2024
@ephys ephys transferred this issue from sequelize/sequelize Mar 27, 2024
@ephys ephys removed the type: docs label Apr 11, 2024
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

5 participants