我正在尝试使用crypto-pouch在我的离子2应用程序中加密PouchDB和CouchDB文档。
在crypto-pouch文档中,它说“如果你复制到另一个数据库,它会在发送到外部数据库之前解密。所以如果你想加密密码,也要确保也设置了密码。” 。这就是我在我的代码中尝试做的事情,如下所示:
init(localDBName, remoteDBName)
{
this._DB = new PouchDB(localDBName);
PouchDB.plugin(CryptoPouch);
this._DB.crypto('a password');
this.remote = remoteDBName;
console.log('Data: init(): PouchDB database opened for localDBName = ' + localDBName + ' : ' + this._DB + ', remoteDBName = ' + this.remote);
// Insert the url for the CouchDB server into the remoteDBName
var realRemoteDB = this.remote.replace("localhost:5984", COUCHDB_SERVER_URL);
console.log('Data: init(): remoteDB path being used is: ' + realRemoteDB);
this._remoteDB = new PouchDB(realRemoteDB);
this._remoteDB.crypto('a password');
let options = {
live: true,
retry: true,
continuous: true
};
return this._DB.sync(realRemoteDB) //No options here -> One time sync
.on('complete', (info) => {
console.log('Data: init(): first one time sync has completed about to do live syncing now');
this.events.publish('SYNC_FINISHED', true); // Let login know we have synced the data
return this._DB.sync(realRemoteDB, options) //Continous sync with options
.on('complete', (info) => {
console.log('***** DATA: init() Complete: Handling syncing complete');
console.dir(info);
})
.on('change', (info) => {
console.log('***** DATA: init() Change: Handling syncing change');
console.dir(info);
})
.on('paused', (info) => {
console.log('***** DATA: init() Paused: Handling syncing pause');
console.dir(info);
})
.on('active', (info) => {
console.log('***** DATA: init() Active: Handling syncing resumption');
console.dir(info);
})
.on('error', (err) => {
console.log('***** DATA: init() Error: Handling syncing error');
console.dir(err);
})
.on('denied', (err) => {
console.log('***** DATA: init() Denied: Handling syncing denied');
console.dir(err);
});
});
}
当我使用Futon查看远程CouchDB服务器上的文档时,文档未按原样加密。