diff --git a/src/wallet-crypto.js b/src/wallet-crypto.js index efb57b672..334f6657a 100644 --- a/src/wallet-crypto.js +++ b/src/wallet-crypto.js @@ -340,8 +340,7 @@ function stretchPassword (password, salt, iterations, keylen) { function pbkdf2 (password, salt, iterations, keylen, algorithm) { algorithm = algorithm || ALGO.SHA1; - var iv = salt.toString('binary'); - return crypto.pbkdf2Sync(password, iv, iterations, keylen, algorithm); + return crypto.pbkdf2Sync(password, salt, iterations, keylen, algorithm); } function hashNTimes (data, iterations) { diff --git a/tests/wallet_crypto_spec.js b/tests/wallet_crypto_spec.js index 3513ebebd..d95327770 100644 --- a/tests/wallet_crypto_spec.js +++ b/tests/wallet_crypto_spec.js @@ -466,6 +466,19 @@ describe('WalletCrypto', () => { it('should not modify the operation is unknown', () => expect(WalletCrypto.cipherFunction('password', 'key', 1000, 'nop')('toto')).toEqual('toto')); }); + describe('pbkdf2', () => { + it('should compute the correct result', () => { + let password = 'password123'; + let salt = new Buffer('acf98ce0f6fb15ac868f0c2cdbc2c263', 'hex'); + let iterations = 5000; + let keylen = 32; + + let result = WalletCrypto.pbkdf2(password, salt, iterations, keylen); + let resultHex = 'f32463775c57e37148b4f54010c794403b34847e99e0b6f381418df09e281900'; + expect(result.toString('hex')).toEqual(resultHex); + }); + }); + describe('scrypt', () => { let observer = {callback (hash) {}};