Sign a JWT with a Private Key using PS256 algorithm

I have a requirement to create and sign a jwt token using a private key and PS256 algorithm. I have search across k6 community but I cant find any extension or plugins that will work with K6 to do this. xk6-crypto extension only supports HMAC sha256, sha384 and sha512 algorithms. I am able to do this using Node Js and Jose framework but k6 does not support running Node js script externally and reuse its return value within k6 script due to being two completely different runtimes.

Is there anyone who is able to achieve this in k6?

Hi @sanchitgupta

Welcome to the forum :tada:

Bad news first: unfortunately, k6 does not support public/private key infrastructure at the moment.

Better news: we have been, however, working actively on implementing the WebCrypto API in recent months, and although the implementation is not complete, we are confident that it should land in k6 as an experimental module in the future. This module will have support for ECDSA P-256, which should address the issue you have at the moment. No ETA on this yet, though.

In the meantime, it’s possible to package k6 scripts in the form of a JS module to use existing node packages. Many of our users do so when a critical feature is not already implemented in k6 but is available in the larger JS ecosystem. Maybe it’s worth giving a try to find a library that supports the functionality you’re looking for and package your script in a way that makes using it possible.

Let me know if that was helpful, and if you have other questions :bowing_man:

1 Like