calvinmetcalf / crypto-pouch

plugin for encrypted pouchdb/couchdb databases
MIT License
243 stars 44 forks source link

The value "NaN" is invalid for option "size" #75

Closed ghost closed 3 years ago

ghost commented 4 years ago

Ubuntu 16.04 Node: 14.4.0 pouch-db: 7.2.2 crypto-pouch: 3.1.3 electron: 7.1.2

import PouchDB from 'pouchdb';
import PouchCrypto from 'crypto-pouch';

const db = new PouchDB(my-db');
db.crypto('some-password')

Results in

  constructor: 'NodeError',
  stack: 'RangeError [ERR_INVALID_OPT_VALUE]: The value "NaN" is invalid for option "size"\n' +
    '    at Function.allocUnsafe (buffer.js:272:3)\n' +
    '    at new Hmac (http://localhost:2003/app.js:210768:21)\n' +
    '    at pbkdf2 (http://localhost:2003/app.js:210813:14)\n' +
    '    at http://localhost:2003/app.js:210670:12'
ghost commented 4 years ago

According to nodejs docs crypto.pbkdf2 have argument key length, before digest, in code must be used old format, this is why this error take place. Currently in package code it is called as follows:

pbkdf2(password, salt, iterations, digest);

which is incorrect.

garbados commented 3 years ago

crypto-pouch no longer uses crypto-browserify so I'm closing this issue. Let me know if you have any further issues!