Using Crypto-Pouch after latest updates


#1

In my app I’m using the plugin crypto-pouch for pouchdb database encryption. This was working without any problems until the last few weeks.

I updated to the last versions of ionic and cordova. Following mostly this article, I started a new test-project. This is working well in browser and on an android device (Google Nexus 9). But if I make the following changes, the problem begins:

First I install the plugin crypto-pouch:

npm install crypto-pouch --save

Then I inserted the plugin in the database provider like this:

import { Injectable } from '@angular/core';
import * as PouchDB from 'pouchdb';
import cordovaSqlitePlugin from 'pouchdb-adapter-cordova-sqlite';
import CryptoPouch from 'crypto-pouch';

PouchDB.plugin(cordovaSqlitePlugin);
PouchDB.plugin(CryptoPouch);

@Injectable()
export class DatabaseProvider {
  private db;

  initDB() {
    this.db = new PouchDB('test.db', { adapter: 'websql' });
    this.db.crypto('pa$$w0rd');
  }
}

The function initDB() is called from app.components.ts like this:

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, database: DatabaseProvider) {
  platform.ready().then(() => { 
    statusBar.styleDefault();
    splashScreen.hide();

    database.initDB();
  });
}

If I’m testing this in browser (Chrome) everything is okay, but on the android device I’m getting the following error:

ERROR Error: Uncaught (in promise): TypeError: "size" argument must be a number
TypeError: "size" argument must be a number
    at assertSize (main.js:15392)
    at allocUnsafe (main.js:15423)
    at Function.Buffer.allocUnsafe (main.js:15437)
    at module.exports (main.js:80244)
    at main.js:122523
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (main.js:4427)
    at t.invoke (polyfills.js:3)
    at r.run (polyfills.js:3)
    at polyfills.js:3
    at assertSize (main.js:15392)
    at allocUnsafe (main.js:15423)
    at Function.Buffer.allocUnsafe (main.js:15437)
    at module.exports (main.js:80244)
    at main.js:122523
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (main.js:4427)
    at t.invoke (polyfills.js:3)
    at r.run (polyfills.js:3)
    at polyfills.js:3
    at c (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (main.js:4418)
    at t.invokeTask (polyfills.js:3)
    at r.runTask (polyfills.js:3)
    at o (polyfills.js:3)
    at invoke (polyfills.js:3)
    at n (polyfills.js:2)

Can you help me, please? I don’t have any ideas, how to solve this. Thanks in advance!


#2

Unrelated, but if you’re hardcoding passwords into your app, there isn’t really any point in encrypting anything with them.


#3

I know, this is quite obviously. But it’s only for testing. In my real app, the password isn’t hard encoded.


#4

Today I made another little update of ionic (3.4.0 -> 3.4.2) and run my project on my android device without option --livereload and it works! Great!

After trying a lot of changes, I don’t know if I tried it without --livereload before this update. I think, I did…

Therefore it seems not to be an issue of crypto-pouch, but of ionic. Is there a way to use --livereload? It might be much more convenient.


#5

The problem exists still. Not only if I use --livereload on an android device, but I’m trying on an iOS device. There’s always the same error.

I’m very frustrated about this. I spent a lot of time in my app and now nothing is working short before I planned to publish it. Is there anybody who can help me?