electron-vue跨平台桌面应用开发实战教程(十二)——集成加密版的sqlite3:sqlcipher
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/David1025/article/details/107945806
本文主要讲解集成及使用sqlcipher,一个可以加密的sqlite。sqlcipher官方npm地址:https://www.npmjs.com/package/@journeyapps/sqlcipher
由于和sqlite的功能一样,只是增加了加密的功能,所以具体安装方法请参照:https://blog.csdn.net/David1025/article/details/104540050,
1. 安装sqlcipher依赖
npm install "@journeyapps/sqlcipher"
安装完成之后,需要再运行一下(否则会出现找不到sqlite3.node)
npm install
2.使用
var sqlite3 = require('@journeyapps/sqlcipher').verbose();
var db = new sqlite3.Database('test.db');
db.serialize(function() {
// Required to open a database created with SQLCipher 3.x
db.run("PRAGMA cipher_compatibility = 3");
db.run("PRAGMA key = 'mysecret'");
db.run("CREATE TABLE lorem (info TEXT)");
var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
for (var i = 0; i < 10; i++) {
stmt.run("Ipsum " + i);
}
stmt.finalize();
db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
console.log(row.id + ": " + row.info);
});
});
db.close();
PRAGMA key = ‘mysecret’” 为设置的密钥
更多资源请关注(自增程序员)