Registry / storage / sqlite-crypto

sqlite-crypto

JSON →
library1.1.0jsnpmunverified

sqlite-crypto v1.1.0 is a Node.js package that provides transparent encryption for SQLite databases using node-sqlite3. It bundles SQLite, eliminating the need for external libraries. Key features include configurable AES encryption (default aes-256-ctr), password protection, and an encrypt offset to reduce redundant decryption/re-encryption. The package wraps sqlite3 methods (run, get, all, etc.) and returns promises. However, it has very limited adoption (released 2018, last update 2020) and no security audit. Compared to alternatives like better-sqlite3 with SQLCipher, sqlite-crypto is less maintained and may have unknown vulnerabilities.

npm install sqlite-crypto
INSTALL
IMPORT
SIG · SQLITE-CRYPTO
S
sqlite-crypto
storagejavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sqlite-crypto
var crypts = require('sqlite-crypto');
import crypts from 'sqlite-crypto'; // ESM not supported
This package is CommonJS only; no ESM exports.
init
var db = crypts.init({ file: 'path', password: 'pwd', algorithm: 'aes-256-ctr', encrypt_offset: 700 });
var db = new crypts.init(); // init is not a constructor
init() is a factory function, not a class constructor.
db.run
db.run({ sql: 'SELECT * FROM table', method: 'all' }).then((error, rows) => {});
db.run('SELECT * FROM table', callback); // arguments must be an object
Queries must be passed as an object with 'sql' and 'method' keys.

Demonstrates initializing an encrypted SQLite database, creating a table, inserting data, and querying rows using promise-based methods.

var crypts = require('sqlite-crypto'); var db = crypts.init({ file: './test.db', password: 'supersecretpassword', algorithm: 'aes-256-ctr', encrypt_offset: 700 }); db.run({ sql: "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)", method: "run" }).then(function(error, response) { if (error) { console.error('Error:', error); } else { console.log('Table created'); } db.close(); }); db.run({ sql: "INSERT INTO users (name) VALUES ('Alice')", method: "run" }); db.run({ sql: "SELECT * FROM users", method: "all" }).then(function(error, rows) { if (error) { console.error('Error:', error); } else { console.log('Rows:', rows); } });
Debug
Known issues
gotchaThe query method parameter must be exactly 'run', 'get', 'all', or 'each' (sqlite3 methods). Any other string will cause an error.
fix
Use valid method strings: 'run', 'get', 'all', 'each'.
affects: >=0.0.0
gotchaThe promise resolves with (error, response) but both are passed as separate arguments, not an object. Many users expect a single result object.
fix
Handle both arguments in .then((error, response) => ...).
affects: >=0.0.0
deprecatedPackage uses node-sqlite3 which is in maintenance mode. The sqlite-crypto package has not been updated since 2020 and may have unpatched security issues.
fix
Consider migrating to better-sqlite3 with SQLCipher or sql.js with encryption.
affects: >=0.0.0
gotchaThe encrypt_offset is in milliseconds, not seconds. Setting it too low may cause excessive disk I/O.
fix
Use a value >= 1000 for production to avoid re-encrypting too frequently.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: db.run is not a function
The crypts.init() returned an object but the user called db.run() before initialization completed or used wrong import.
fix
Ensure you require('sqlite-crypto') correctly and call crypts.init() first. Check that the returned object has a run method.
Error: SQLITE_ERROR: no such table: ...
Querying a table that does not exist in the encrypted database.
fix
Create the table first using a CREATE TABLE statement with method 'run'.
Error: Password must be a string
Missing or non-string password in init options.
fix
Provide a string password: init({ password: 'mysecret' })
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
node-sqlite3requiredProvides SQLite bindings; sqlite-crypto wraps its methods for encryption.
Agent activity
42 hits · last 30 days
node
38
OpenAI (training)
1
Resources