我希望制作一个使用sqlite3作为数据库的小型electron应用程序。我已经安装了sqlite3。
现在我想加密数据库,特别是在Windows平台上如何操作?
npm install sqlite3
并使用node-gyp重新构建,以便与electron一起使用,现在一切都很顺利。现在我想加密数据库,特别是在Windows平台上如何操作?
npm install sqlite3
并使用node-gyp重新构建,以便与electron一起使用,现在一切都很顺利。是的,这个问题有点老了,但如果还有人需要答案,这可能会对他们有所帮助。
您可以使用@journeyapps/sqlcipher
在electron应用程序中启用sqlite3数据库的加密。
如果您使用任何JavaScript ORM sequelize
,则可以像下面显示的那样配置它以使用@journeyapps/sqlcipher
作为sqlite3数据库引擎。
const sequelize = new Sequelize(null, null, 'your-encryption-key', {
dialect: 'sqlite',
dialectModulePath: '@journeyapps/sqlcipher',
storage: 'path/to/db.sqlite'
})
这对我有效 :)
这里是一个示例应用程序,它使用带有sqlchiper包装器的sqlite3。
SQLCipher
和sqleet
(ChaCha20-Poly1305),并且可以直接使用SQLite3MultipleCiphers。它经过了充分的测试,速度快,几乎和原始库一样完美。我使用了:
我的个人应用程序使用“NODE JS”和ORM“SEQUELIZE”编写的代码:
更多信息https://sequelize.org/master/
const db_user = new Sequelize(
database: "sdb",
username: "",
password: "mysecret",
options: {
dialect: "sqlite",
dialectModulePath: '@journeyapps/sqlcipher',
storage: "src/dbs/securedb.db",
}
);
// SQLCipher config
db_user.query("PRAGMA cipher_compatibility = 4");
/*db_user.query("PRAGMA cipher_use_hmac = ON");
db_user.query("PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA1");
db_user.query("PRAGMA cipher_hmac_algorithm = HMAC_SHA1");
db_user.query("PRAGMA cipher_page_size = 4096");
db_user.query("PRAGMA cipher = 'aes-256-cbc'");
db_user.query("PRAGMA kdf_iter = 256000");
db_user.query("PRAGMA cipher_plaintext_header_size = 0");*/
db_user.query("PRAGMA key = 'mysecret'");
async function connect(){
try {
await db_user.authenticate();
return console.log('Connection has been established successfully.');
} catch (error) {
return console.error('Unable to connect to the database:', error);
}
}
function loadModels(){
var MdUser = db_user.define("user",{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
allowNull: false,
unique: true,
primaryKey: true
},
name:{
type: DataTypes.STRING,
allowNull: false
}
});
db_user.sync(
//{ force: true }
{ alter: true }
);
}
connect()
.then(loadModels())
使用DB-Browser-SQLite https://sqlitebrowser.org,您可以打开新的/定义的SQL-chiper数据库。
您可以使用Win10上的HexDump Viewer进行比较/验证结果。https://www.saltybrine.com/hexdump32.htm