react-native-quick-crypto icon indicating copy to clipboard operation
react-native-quick-crypto copied to clipboard

pbkdf2 is undefined

Open michaelessiet opened this issue 1 year ago • 5 comments

In version 0.7.0rc6 pbkdf2 is seen as undefined. I get this error whenever I try to call it from my app. Screen Shot 2024-05-20 at 13 51 30 PM

With further analysis I noticed that the issue wasn't from the app but from the latest version of the package. The code snippet below is enough to reproduce:

import qc from 'react-native-quick-crypto'

const salt = toUtf8Bytes("abcd", UnicodeNormalizationForm.NFKD)

qc.pbkdf2Sync(toUtf8Bytes("abcd", UnicodeNormalizationForm.NFKD), salt, 2048, 64, "SHA-512")

Not sure what changed from v0.6.1 but I'm happy to provide more information if you're unable to reproduce

michaelessiet avatar May 20 '24 12:05 michaelessiet

perhaps the partial subtle implementation is implicated here. it might be good to give users fine grained control over whether they want to adopt subtle or not.

shamilovtim avatar May 20 '24 22:05 shamilovtim

perhaps the partial subtle implementation is implicated here. it might be good to give users fine grained control over whether they want to adopt subtle or not.

Why subtle here? He's using the crypto method, not crypto.subtle. Granted, subtle is what has changed recently, but I haven't found anything in the commits that is a smoking gun (yet). Changes around algo name "SHA-512" should still result in sha512 being sent into C++.

I've added a test in a branch, and it passes: https://github.com/boorad/react-native-quick-crypto/commit/6dc72cfe0c16a934e25971c9dcfee60010256880

Does this pass for everyone else, in the example app?

boorad avatar May 21 '24 01:05 boorad

Screen Shot 2024-05-21 at 13 00 27 PM 15 failed and the rest passed. No undefined though, just mismatched expected values. Can I take this as a sign that the undefined issue will be resolved in the new RC release?

michaelessiet avatar May 21 '24 12:05 michaelessiet

Sorry, this was unclear unless you're working in the codebase all the time...

Look at the last line in the log. It should say "pass: fns should not be undefined, #322" or similar. This shows that the new test passes, and that pbkdf2 is not undefined and that the call to pbkdf2Sync() gives the proper result. So something is wrong with your app, because the Example App can run your code just fine.

boorad avatar May 21 '24 13:05 boorad

Hmm, maybe is it because I'm substituting crypto with it and assigning pbkdf2Sync to crypto's pbkdf2? But it's still weird that it works for v0.6.1 but breaks on the latest RC. I'll try again later in the week as it's not an urgent thing right now, it's just halted our Expo 51 update.

michaelessiet avatar May 21 '24 16:05 michaelessiet

Any update here? Maybe look at our crypto polyfill code and use that or duplicate it?

boorad avatar Jul 16 '24 10:07 boorad

Upgrading to the latest version fixes this. Thanks. Sorry for the late response

michaelessiet avatar Jul 16 '24 11:07 michaelessiet