v0.9.2 switched to correct version of encrypted database

This commit is contained in:
2026-03-13 15:30:57 -04:00
parent e02cf69745
commit 5301d8a525
7 changed files with 23 additions and 19 deletions

View File

@@ -74,7 +74,7 @@ if (header.toString('ascii') !== MAGIC) {
let Database;
try {
Database = require('better-sqlite3-sqlcipher');
Database = require('better-sqlite3-multiple-ciphers');
} catch (e) {
console.error('ERROR: better-sqlite3-sqlcipher is not installed.');
console.error('Run: npm install better-sqlite3-sqlcipher');
@@ -95,20 +95,20 @@ try {
console.log('Step 1/4 Opening plain database...');
const plain = new Database(DB_PATH);
// Create the encrypted copy using SQLCipher ATTACH + sqlcipher_export
// Create encrypted copy using sqlcipher_export via ATTACH
console.log('Step 2/4 Encrypting to temporary file...');
const safeKey = DB_KEY.replace(/'/g, "''");
plain.exec(`
ATTACH DATABASE '${encPath}' AS encrypted KEY '${safeKey}';
SELECT sqlcipher_export('encrypted');
DETACH DATABASE encrypted;
`);
plain.exec(`ATTACH DATABASE '${encPath}' AS encrypted KEY '${safeKey}'`);
plain.exec(`SELECT sqlcipher_export('encrypted')`);
plain.exec(`DETACH DATABASE encrypted`);
plain.close();
// Verify the encrypted file opens correctly
// Verify the encrypted file opens correctly with cipher settings
console.log('Step 3/4 Verifying encrypted database...');
const enc = new Database(encPath);
enc.pragma(`key = '${safeKey}'`);
enc.pragma(`cipher='sqlcipher'`);
enc.pragma(`legacy=4`);
enc.pragma(`key='${safeKey}'`);
const count = enc.prepare("SELECT COUNT(*) as n FROM sqlite_master").get();
enc.close();
console.log(` OK — ${count.n} objects found in encrypted DB`);