Encryption 如何实现sqlcipher加密离子工程
我想在Ionic project上加密我的数据库,因为如果不加密,我可以在任何设备中安装apk并以root用户身份访问存储,我可以获取.db文件并导入到任何sql编辑器(如sqlbrowser),之后我可以看到我的所有数据和表结构 因此,我们必须对ouer数据库进行加密 主要的问题是,很多人都在谈论cordova插件SQLCipher,但是没有教程或者下面的步骤可以在Ionic项目上实现,只是你可以在Android或iOS上找到这些步骤 这是否意味着我们可以在爱奥尼亚项目的本机部分实现数据库加密?解决方案不清楚,也不清楚它是如何工作的 链接 这是我的测试代码:Encryption 如何实现sqlcipher加密离子工程,encryption,sqlite,ionic-framework,cordova-plugins,sqlcipher,Encryption,Sqlite,Ionic Framework,Cordova Plugins,Sqlcipher,我想在Ionic project上加密我的数据库,因为如果不加密,我可以在任何设备中安装apk并以root用户身份访问存储,我可以获取.db文件并导入到任何sql编辑器(如sqlbrowser),之后我可以看到我的所有数据和表结构 因此,我们必须对ouer数据库进行加密 主要的问题是,很多人都在谈论cordova插件SQLCipher,但是没有教程或者下面的步骤可以在Ionic项目上实现,只是你可以在Android或iOS上找到这些步骤 这是否意味着我们可以在爱奥尼亚项目的本机部分实现数据库加密
.factory('NotesDataService', function($cordovaSQLite, $ionicPlatform) {
var db, dbName = "noteDemo.db"
function useWebSql() {
db = window.openDatabase(dbName, "1.0", "Note database", 200000)
console.info('Using webSql')
}
function useSqlLite() {
db = $cordovaSQLite.openDB({
name: dbName
})
console.info('Using SQLITE')
}
function initDatabase() {
$cordovaSQLite.execute(db, 'CREATE TABLE IF NOT EXISTS T_NOTE (id integer primary key, title, content)')
.then(function(res) {
}, onErrorQuery)
}
$ionicPlatform.ready(function() {
if (window.cordova) {
useSqlLite()
} else {
useWebSql()
}
initDatabase()
})
function onErrorQuery(err) {
console.error(err)
}
return {
createNote: function(note) {
return $cordovaSQLite.execute(db, 'INSERT INTO T_NOTE (title, content) VALUES(?, ?)', [note.title, note.content])
},
updateNote: function(note) {
return $cordovaSQLite.execute(db, 'UPDATE T_NOTE set title = ?, content = ? where id = ?', [note.title, note.content, note.id])
},
getAll: function(callback) {
$ionicPlatform.ready(function() {
$cordovaSQLite.execute(db, 'SELECT * FROM T_NOTE').then(function(results) {
var data = []
for (i = 0, max = results.rows.length; i < max; i++) {
data.push(results.rows.item(i))
}
callback(data)
}, onErrorQuery)
})
},
deleteNote: function(id) {
return $cordovaSQLite.execute(db, 'DELETE FROM T_NOTE where id = ?', [id])
},
getById: function(id, callback) {
$ionicPlatform.ready(function() {
$cordovaSQLite.execute(db, 'SELECT * FROM T_NOTE where id = ?', [id]).then(function(results) {
callback(results.rows.item(0))
})
})
}
}
})
// Even if I add the argument like that, didn 't work ;
db = $cordovaSQLite.openDB({
name: dbName,
password: "secret2"
})
.factory('NotesDataService',函数($cordovaSQLite,$ionicPlatform){
var db,dbName=“noteDemo.db”
函数useWebSql(){
db=window.openDatabase(dbName,“1.0”,“Note数据库”,200000)
console.info('使用webSql')
}
函数useSqlLite(){
db=$cordovaSQLite.openDB({
名称:dbName
})
console.info('使用SQLITE')
}
函数initDatabase(){
$cordovaSQLite.execute(db,'createtable IF NOTE(id integer主键、标题、内容)'
.然后(功能(res){
},onErrorQuery)
}
$ionicPlatform.ready(函数(){
如果(窗口科尔多瓦){
useSqlLite()
}否则{
useWebSql()
}
initDatabase()
})
函数onErrorQuery(err){
控制台错误(err)
}
返回{
createNote:函数(注释){
返回$cordovaSQLite.execute(db,'INSERT INTO T_NOTE(title,content)值(?,),[NOTE.title,NOTE.content])
},
updateNote:函数(注意){
返回$cordovaSQLite.execute(db,'UPDATE T_NOTE set title=?,content=?where id=?',[NOTE.title,NOTE.content,NOTE.id])
},
getAll:函数(回调){
$ionicPlatform.ready(函数(){
$cordovaSQLite.execute(db,'SELECT*FROM T_NOTE')。然后(函数(结果){
var数据=[]
对于(i=0,max=results.rows.length;i
步骤1:将插件添加到爱奥尼亚项目中
cordova plugin add cordova-sqlcipher-adapter
步骤2:添加sqlitePlugin
function useWebSql() {
db = window.sqlitePlugin.openDatabase({name: 'dbName.db', key: 'Enter key that you want', location: 'default'});
//db = window.openDatabase(dbName, "1.0", "Note database", 200000)
console.info('Using webSql')
}
function useSqlLite() {
db = window.sqlitePlugin.openDatabase({name: 'dbName.db', key: 'Enter key that you want', location: 'default'});
console.info('Using SQLITE')
}
function initDatabase(){
//$cordovaSQLite.execute(db, 'CREATE TABLE IF NOT EXISTS T_NOTE (id integer primary key, title, content)')
//.then(function(res){
// }, onErrorQuery)
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS T_NOTE (id integer primary key, title, content)',function(tx,results){},onErrorQuery);
});
}
$ionicPlatform.ready(function () {
if(window.cordova){
useSqlLite()
} else {
useWebSql()
}
initDatabase()
})
function onErrorQuery(err){
console.error(err)
}