scrypt-kdf icon indicating copy to clipboard operation
scrypt-kdf copied to clipboard

Buffer.from() does not appear to work

Open mdhornet90 opened this issue 6 years ago • 5 comments

I attempted to incorporate version 2.0.1 of this library into my project, but hit a snag in the following code:

import scrypt from 'scrypt-kdf'
...
const storedKdf = Buffer.from(storedPassword, 'hex');
return scrypt.verify(storedKdf, passwordToTest);

which results in an error on this line in the scrypt library: https://github.com/chrisveness/scrypt-kdf/blob/f557392d652c809a9a7a322fa55893958733d59c/scrypt.js#L126

I initially thought it was my use of 'hex' as the encoding, but changing both the password storage and decoding to 'base64' yields the same error. As far as I know a Node.js Buffer object is also an instance of Uint8Array, so I'm wondering what's causing this issue.

mdhornet90 avatar Oct 01 '19 00:10 mdhornet90

Could you try checking the types & values of storedPassword & storedKdf: i.e.

console.log('storedPassword', typeof storedPassword, storedPassword);
console.log('storedKdf', typeof storedKdf, storedKdf);

chrisveness avatar Oct 02 '19 15:10 chrisveness

@mdhornet90

I ran into a similar issue when writing unit tests with Jest for this lib. So if you've this issue when running tests it's probably not scrypt-kdf.

https://github.com/facebook/jest/issues/4422

Jimjardland avatar Oct 14 '19 12:10 Jimjardland

@Jimjardland thanks for that suggestion: I don't think I would have worked that one out!

@mdhornet90 would that explain your issues? Are you using Jest for your tests?

I have added an indication of the type received to the parameter type checks to assist with any such issues in the future.

chrisveness avatar Oct 15 '19 18:10 chrisveness

@Jimjardland I ran into the same issue. Could you please share your solution?

alexeychikk avatar Dec 26 '19 09:12 alexeychikk

@alexeychikk

Sorry for the later answer, didn't notice until now.

I made a custom Jest environment where i included Uint8Array and ArrayBuffer.

You can find it here: https://github.com/Jimjardland/custom-jest-environment

Jimjardland avatar Jan 23 '20 09:01 Jimjardland