m4heshd/better-sqlite3-multiple-ciphers

GitHub: m4heshd/better-sqlite3-multiple-ciphers

一个为 Node.js 提供多重加密支持的高性能 SQLite 库,用于安全地存储敏感数据。

Stars: 235 | Forks: 36

# better-sqlite3 多重加密 [![NPM 版本](https://img.shields.io/npm/v/better-sqlite3-multiple-ciphers?logo=npm&color=cc3838&style=for-the-badge)](https://www.npmjs.com/package/better-sqlite3-multiple-ciphers) [![下载量](https://img.shields.io/npm/dt/better-sqlite3-multiple-ciphers?logo=DocuSign&logoColor=FFF&color=2757c4&style=for-the-badge)](https://www.npmjs.com/package/better-sqlite3-multiple-ciphers) [![构建状态](https://img.shields.io/github/actions/workflow/status/m4heshd/better-sqlite3-multiple-ciphers/test.yml?branch=master&label=Build%2FTest&logo=github&style=for-the-badge)](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/actions/workflows/test.yml) Node.js 中最快、最简单的 SQLite 库。此特定分支通过 [SQLite3MultipleCiphers](https://github.com/utelle/SQLite3MultipleCiphers) 支持多密码加密。查看[使用方法](#usage)以了解更多信息。 ## 当前版本 - 稳定版 - **better-sqlite3-multiple-ciphers** - [`12.10.0`](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/releases/tag/v12.10.0) - **better-sqlite3** - [`12.10.0`](https://github.com/JoshuaWise/better-sqlite3/releases/tag/v12.10.0) - **SQLite** - [`3.53.1`](https://www.sqlite.org/releaselog/3_53_1.html) - **SQLite3 Multiple Ciphers** - [`2.3.4`](https://github.com/utelle/SQLite3MultipleCiphers/releases/tag/v2.3.4) - 测试版 - **better-sqlite3-multiple-ciphers** - [`11.0.0-beta.0`](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/releases/tag/v11.0.0-beta.0) - **better-sqlite3** - [`11.0.0`](https://github.com/JoshuaWise/better-sqlite3/releases/tag/v11.0.0) - **SQLite** - [`3.46.0`](https://www.sqlite.org/releaselog/3_46_0.html) - **SQLite3 Multiple Ciphers** - [`1.8.5`](https://github.com/utelle/SQLite3MultipleCiphers/releases/tag/v1.8.5) ## 帮助本项目保持强大!💪 `better-sqlite3` 每天被成千上万的开发者和工程师使用。无数个夜晚和周末都投入到保持本项目的强大和可靠中,直到现在,从未要求过补偿或资助。如果你的公司在使用 `better-sqlite3`,请建议你的经理考虑支持这个项目。 ## 其他库的对比 | |查询 1 行  `get()` |查询 100 行   `all()`  |查询 100 行 `iterate()` 逐条|插入 1 行 `run()`|在事务中插入 100 行| |---|---|---|---|---|---| |better-sqlite3|1x|1x|1x|1x|1x| |[sqlite](https://www.npmjs.com/package/sqlite) 和 [sqlite3](https://www.npmjs.com/package/sqlite3)|慢 11.7 倍|慢 2.9 倍|慢 24.4 倍|慢 2.8 倍|慢 15.6 倍| ## 安装说明 ### 稳定版 ``` npm install better-sqlite3-multiple-ciphers ``` ### 测试版 ``` npm install better-sqlite3-multiple-ciphers@beta ``` ## 使用方法 ``` const db = require('better-sqlite3-multiple-ciphers')('foobar.db', options); const row = db.prepare('SELECT * FROM users WHERE id = ?').get(userId); console.log(row.firstName, row.lastName, row.email); ``` 虽然不是必需的,但[出于性能考虑,通常设置 WAL pragma 非常重要](https://github.com/WiseLibs/better-sqlite3/blob/master/docs/performance.md)。 ``` db.pragma('journal_mode = WAL'); ``` ##### ES6 模块表示法: ``` import Database from 'better-sqlite3-multiple-ciphers'; const db = new Database('foobar.db', options); db.pragma('journal_mode = WAL'); ``` ### 加密 可以使用 `key` 和 `rekey` `PRAGMA` 语句轻松加密和解密数据库。 **运行此命令将使用默认密码(sqleet)加密数据库:** ``` const db = require('better-sqlite3-multiple-ciphers')('foobar.db', options); db.pragma(`rekey='secret-key'`); db.close(); ``` **读取加密数据库(假设使用默认密码):** ``` const db = require('better-sqlite3-multiple-ciphers')('foobar.db', options); db.pragma(`key='secret-key'`); const row = db.prepare('SELECT * FROM users WHERE id = ?').get(userId); console.log(row.firstName, row.lastName, row.email); ``` **读取由 [DB Browser for SQLite](https://github.com/sqlitebrowser/sqlitebrowser) 等工具创建的加密数据库 _(旧版 SQLCipher)_ :** ``` const db = require('better-sqlite3-multiple-ciphers')('foobar.db', options); db.pragma(`cipher='sqlcipher'`) db.pragma(`legacy=4`) db.pragma(`key='secret-key'`); const row = db.prepare('SELECT * FROM users WHERE id = ?').get(userId); console.log(row.firstName, row.lastName, row.email); ``` 如果你想创建一个新的加密数据库,使其能够使用 DB Browser for SQLite 打开,也应使用相同的方法。 你也可以使用 [`key()`](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/blob/master/docs/api.md#keybuffer---number) 和 [`rekey()`](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/blob/master/docs/api.md#rekeybuffer---number) 函数进行加密和解密任务。 **GUI 数据库编辑器:** 尽管 `better-sqlite3-multiple-ciphers` 支持打开使用 [DB Browser for SQLite](https://github.com/sqlitebrowser/sqlitebrowser) 创建的数据库,但它仅支持创建/编辑旧版 SQLCipher 数据库,这意味着你很可能无法在 DB Browser for SQLite 中打开使用 `better-sqlite3-multiple-ciphers` 创建的数据库。 要可视化编辑使用 `better-sqlite3-multiple-ciphers` 创建的数据库(无论其密码配置如何),建议使用 [SQLiteStudio](https://github.com/pawelsalawa/sqlitestudio) 之类的工具,因为它底层也使用了 [SQLite3MultipleCiphers](https://github.com/utelle/SQLite3MultipleCiphers)。 ### 更多加密信息,请阅读 [SQLite3MultipleCiphers 文档](https://utelle.github.io/SQLite3MultipleCiphers/)。 ## 为什么我应该使用这个库而不是 [node-sqlite3](https://github.com/mapbox/node-sqlite3)? - `node-sqlite3` 对于 CPU 密集型或序列化的任务使用异步 API。这不仅是糟糕的设计,还浪费大量资源。它还会导致 [mutex thrashing](https://en.wikipedia.org/wiki/Resource_contention),这对性能有灾难性的影响。 - `node-sqlite3` 暴露了底层(C 语言)内存管理函数。`better-sqlite3` 以 JavaScript 的方式处理,让垃圾回收器负责内存管理。 - `better-sqlite3` 更易于使用,并且为一些在 `node-sqlite3` 中非常困难或不可能完成的操作提供了很好的工具。 - 在大多数情况下,`better-sqlite3` 比 `node-sqlite3` 快得多,在所有其他情况下速度相当。 #### 什么时候这个库不太合适? 在大多数情况下,如果你试图用 `better-sqlite3` 无法合理完成的事情,那么用 SQLite 通常也无法合理完成。例如,如果你正在执行需要一秒钟才能完成的查询,并且你预计会有许多并发用户执行这些查询,那么无论多少异步性都无法让你摆脱 SQLite 的序列化本质。幸运的是,SQLite 非常*非常*快。通过适当的索引,我们已经能够在 60 GB 的数据库中实现每秒超过 2000 次的 5 表连接查询,每次查询处理 5–50 KB 的实际数据。 如果你遇到性能问题,最可能的原因是查询效率低下、索引不当或缺乏 [WAL 模式](./docs/performance.md)——而不是 `better-sqlite3` 本身。然而,在某些情况下 `better-sqlite3` 可能不合适: 对于这些情况,你可能应该使用一个成熟的 RDBMS,例如 [PostgreSQL](https://www.postgresql.org/)。 ## 升级说明 升级你的 `better-sqlite3-multiple-ciphers` 依赖可能会引入破坏性变更,可能出现在 `better-sqlite3-multiple-ciphers` API 中(如果你升级到新的[主版本](https://semver.org/)),或者存在于你现有数据库与底层 SQLite 版本之间。在升级之前,请查看: * [`better-sqlite3-multiple-ciphers` 发行说明](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/releases) * [SQLite 发行历史](https://www.sqlite.org/changes.html) # 文档 - [API 文档](./docs/api.md) - [性能](./docs/performance.md)(另请参见[基准测试结果](./docs/benchmark.md)) - [64 位整数支持](./docs/integer.md) - [Worker 线程支持](./docs/threads.md) - [不安全模式(高级)](./docs/unsafe.md) - [SQLite 编译(高级)](./docs/compilation.md) # 许可证 [MIT](./LICENSE)
标签:better-sqlite3, CMS安全, GNU通用公共许可证, JavaScript, MITM代理, Node.js, npm包, ProjectDiscovery, SQLite, SQLite3MultipleCiphers, 加密, 加密算法, 多密码加密, 安全, 库, 应急响应, 性能优化, 数据保护, 数据库, 数据库加密, 检测绕过, 漏洞扫描器, 自定义脚本, 超时处理