electron-vue跨平台桌面应用开发实战教程(十二)——集成加密版的sqlite3:sqlcipher
程序员文章站
2022-03-16 20:04:59
本文主要讲解集成及使用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....
本文主要讲解集成及使用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’" 为设置的密钥
更多资源请关注(自增程序员)
本文地址:https://blog.csdn.net/David1025/article/details/107945806