apigee / trireme

Embed Node.js inside a Java Virtual Machine
Other
479 stars 48 forks source link

Fix crypto.pbkdf2* to work like node.js #169

Closed whitlockjc closed 7 years ago

whitlockjc commented 7 years ago

Whenever attempting to use crypto.pbkdf2* APIs, any time a Buffer was used as an input the results from Trireme would differ from node.js and the result is that the verification would fail. This commit fixes that by making the following changes:

  1. io.apigee.trireme.core.modules.Crypto$PBKDF2 now treats its input arguments as Buffer objects.
  2. io.apigee.trireme.kernel.util.StringUtils#stringToBuffer now properly handles base64 encoded strings such that the returned ByteBuffer only includes populated bytes. Before this change, if the actual bytes in the Node.js Buffer were less than the ByteBuffer allocated, the returned byte[] would have extra bytes on the end and this broke crypto.pbkdf2*.
  3. Tests were added to prove crypto.pbkdf2* works identically to node.js and the previously commented out PBKDF2 tests were uncommented.
whitlockjc commented 7 years ago

Closing in favor of #170.