diff --git a/index.js b/index.js index 98533ca..f8f38b3 100644 --- a/index.js +++ b/index.js @@ -13,13 +13,11 @@ module.exports = { _createHmac }; -function _encryptLogin(login, masterPassword) { +function _encryptLogin(login, masterPassword, {iterations = 8192, keylen = 32}={}) { return new Promise((resolve, reject) => { if (!login || !masterPassword) { reject('login and master password parameters could not be empty'); } - const iterations = 8192; - const keylen = 32; crypto.pbkdf2(masterPassword, login, iterations, keylen, 'sha256', (error, key) => { if (error) { reject('error in pbkdf2'); diff --git a/tests/api.tests.js b/tests/api.tests.js index 361cf70..6944284 100644 --- a/tests/api.tests.js +++ b/tests/api.tests.js @@ -9,12 +9,37 @@ describe('LessPass', function () { }); }); + it('should allow to customize number of iterations', function (done) { + LessPass.encryptLogin('test@example.org', 'password', {iterations: 4096}).then(function (encryptedLogin) { + assert.equal('0a91208545e3aa4935d3a22984ca097a7669259a04d261ac16361bdc1a2e960f', encryptedLogin); + done(); + }); + }); + + it('should allow to customize key length', function (done) { + LessPass.encryptLogin('test@example.org', 'password', {keylen: 16}).then(function (encryptedLogin) { + assert.equal('d8af5f918db6b65b1db3d3984e5a400e', encryptedLogin); + done(); + }); + }); + + it('should allow to customize iterations and key length', function (done) { + LessPass.encryptLogin('test@example.org', 'password', { + iterations: 4096, + keylen: 16 + }).then(function (encryptedLogin) { + assert.equal('0a91208545e3aa4935d3a22984ca097a', encryptedLogin); + done(); + }); + }); + it('should allow utf8 parameter', function (done) { LessPass.encryptLogin('test@example.org', '♥ LessPass ♥').then(function (encryptedLogin) { assert.equal('997fe81d3d0db236e039c75efdb487f17a902fdf94f9dacaa9884329c85d9651', encryptedLogin); done(); }); }); + it('auto generated encrypt login tests', function () { var promises = []; var passwords = [ @@ -105,6 +130,8 @@ describe('LessPass', function () { assert.equal('azYS7,olOL2]', generatedPassword); }) }); + + it('auto generated render password tests', function () { var promises = []; var passwords = [