-
Notifications
You must be signed in to change notification settings - Fork 28
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
Cannot Create Legacy SQLCipher Encrypted DB #88
Comments
Can you create a minimal reproducible repo so I can check it out? |
embarrassed to say I don't know how. |
@petef19 If it's only those lines of code you tried, there's an issue. You have to close the DB properly for the encryption to stick. You aren't doing that on the snippet you posted. |
@m4heshd |
@petef19 Just realized that your new DB is empty. New databases in SQLite are 0-byte files which means any 0-byte file can be a database. So when you try to encrypt it, there's no data to encrypt. All you have to do is create a schema or insert data into your DB. Try this for an example: import Database from 'better-sqlite3-multiple-ciphers';
const db = new Database('test.db', {verbose: console.log});
db.pragma(`cipher='sqlcipher'`);
db.pragma(`legacy=4`);
db.pragma(`key='secret-key'`);
db.prepare(
`
CREATE TABLE IF NOT EXISTS "person"
(
"id" TEXT,
"name" TEXT,
"age" REAL,
PRIMARY KEY ("id")
)
`
).run();
db.prepare(
`
INSERT
OR IGNORE INTO "person"
VALUES (@id,
@name,
@age)
`
).run({
id: '1',
name: 'Jane',
age: '25'
});
console.log(
db.prepare(`SELECT * FROM "person"`).all()
);
db.close(); This will create an encrypted DB in the first run and will fetch data in all of the following runs. Also keep in mind, that simply setting an SQLite PRAGMA would also do the job since that makes the new file an actual database. Try the following as well. import Database from 'better-sqlite3-multiple-ciphers';
const db = new Database('test.db', {verbose: console.log});
db.pragma(`cipher='sqlcipher'`);
db.pragma(`legacy=4`);
db.pragma(`key='secret-key'`);
db.pragma('journal_mode=WAL');
db.close(); |
That's really odd because it all works perfectly fine for me. Make sure to delete the previous |
I do delete the test.db file after every test run so that a new file is created every time. |
You also could've missed one other tiny detail. DB4S has two versions. One's compiled with plain SQLite3 and the other with SQLCipher. You might be trying to open the DB in the plain version. 🤔 And when you're trying to open it in the SQLCipher version, ensure the header values reflect the following. |
🤣 yup, you were absolutely right! I never realized there is a separate DB4S exe for the SQLCipher version, holy cow! okay, it works now - THANK YOU! 😄 so, can you comment on if there is any major concerns or differences for these encryption algos: I'm not a fan of SQLite Studio which is why I'm asking if (1) or (2) raise any concern? Thanks! |
I personally stick to But then you do run into the issue of not having a good compatible tool to manipulate your database visually. I used to write my own separate programs for that specific task but, ended up setting up my own custom driver for the IDE I use since JetBrains IDEs have a really advanced data source management plugin built-in. |
nice, thanks!
did you publish the JB addon?
did a quick & dirty performance test between three (3) bs3 algos in Node that included these tasks: results:
from that, they all look equal. Thanks! |
Nevermind. Curiosity got the best of me. JetBrains IDE's custom data source configuration is undocumented. Just spent 3.5 hours to set this up flawlessly. It took an insane amount of effort to tests and create these template URLs. 🥵 First, head over to this repo and download both the JDBC driver and Then comes the infuriating URL Template portion. I managed to create the following URL Templates to cover every cipher scheme and any scenario. Multi-cipher:
This should be enough. The following are just optional. Sqleet:
SQLCipher:
After this, you can simply create a Data Source using that custom driver. Following is a screenshot of the active data source of the very same example application I wrote for you yesterday. It's using Please consider a donation for my time and effort if this library and my support served you well. 😌
Unfortunately, It's not as simple as that. Also, you need much larger test scenarios to observe any actual difference. You can clearly see from the tests I linked, that AES operations are much slower. This also depends on hardware because AES cryptography is heavily hardware-accelerated unlike If you test further, you'll find that opening even a smaller database encrypted using SQLCipher is a way more expensive task than opening a sqleet DB because of the resource-heavy iterations it performs for key derivation. That kind of performance matters when you develop scalable and adaptable software. This is why
Unfortunately, there's only one, that was also published by me 😄, now deprecated. This is the reality of using third-party libraries. You just never know when you'll run into trouble 🤷🏻. Been developing software practically my whole life and I can't even count how many times I had to write my own libraries because of this very same reason. |
your timing... is impeccable 😆 In case anybody else reads this here, the one thing that held me up was that one has to also specify the Thanks regarding your input regarding performance! |
@petef19 That's great. Keeping this issue open for the moment because I'd like to add this process to the documentation at some point. |
@m4heshd is there any way you could post these test timings and have them persisted? It says the logs have all expired so cannot view them. Thanks! |
You can always take a look at the log of the latest test runs from the |
Sorry for the dumb question but is there a specific workflow action I should look at in there for the benchmarking of the different encryption options? I was looking for the timings you referred to above recommending chacha as the fastest (have to show my team haha) :) thanks! |
@GitMurf It's always this portion of any test. |
Following along the info stated in the readme file to a create a legacy SQLCipher encrypted DB that can be opened in SQLIte Browser.
Running this code:
creates a valid sqlite3 db but that db is NOT encrypted, SQLIte Browser does NOT ask a for a password or key, it directly opens the empty db. Navicat does the same thing.
What am I doing wrong?
Win 10 x64
Node 16.13.2
better-sqlite3-multiple-ciphers: 9.4.1
Also, is there a list of operating systems that are known to work or not work with this package?
Thanks!
The text was updated successfully, but these errors were encountered: