k6

Include the external NPM crypto2 library exception

I am using browserify for the following npm library into a single js file.

const publicKey = await crypto2.readPublicKey(‘key.pub’);
const encrypted = await crypto2.encrypt.rsa(‘the native web’, publicKey);

await is a reserved word error shown in the terminal.

After that, I tried to remove the await keyword, I need to wait more than 2 minutes and it throws the exception below.

TypeError: Object has no member ‘setPrototypeOf’ at <js_file>:17547:30(344)

Any suggestion?

Hi,

unfortunately I don’t think this library will work with k6. The main reason is the lack of an event loop in k6, so while a lot of NPM modules will work after being run through Browserify, modules that rely on async/await will not. Implementing an event loop in k6 is on the roadmap, but not in the near future.

For your setPrototypeOf error see this comment on a related issue, where the suggested fix is to use an alternative polyfill. So you can try loading that module manually and let us know if it fixes it.

Besides this, is there a particular reason you need to use crypto2? k6 has a built-in crypto library you could use instead if it fits your use case.

Hope this helps,

Ivan

Hi @imiric

Thanks for your valuable feedback. However, I cannot find a similar method from crypto to encrypt with rsa together the public key.

Ah, yes, RSA is not part of the supported algorithms yet. :frowning: There are a few reasons for this, see this comment for details.

Feel free to experiment with other libraries or with that alternative polyfill, but unfortunately k6 doesn’t have built-in RSA support.