【发布时间】:2016-04-04 13:26:29
【问题描述】:
我想在 Ionic 项目上加密我的数据库,因为没有加密我可以在任何设备中安装 apk 并以 root 身份访问存储,然后我可以获取 .db 文件并导入到任何 sql 编辑器,如 sqlbrowser 之后我可以看到我所有的数据和表结构!
因此,我们必须加密我们的数据库,
主要问题,很多人都在谈论cordova插件SQLCipher,但是在Ionic项目上没有教程或以下步骤来实现,你可以在Android或iOS上找到步骤..
这是否意味着我们可以在 Ionic 项目的本机部分实现数据库加密或什么?解决方案不清楚,或者它是如何工作的!
npm plugin的链接
这是我的测试代码:
.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"
})
【问题讨论】:
标签: encryption sqlite ionic-framework cordova-plugins sqlcipher