Are 512 Bit Keys (public private key pair) for JWT (NodeJS) Secure Enough

Viewed 2118

I've been refactoring our JWT signing and verifying structure to something more secure. I've used this article as a starting place (and taking the suggestion of using the RS256 algorithm as opposed to the HS256 algorithm): https://medium.com/@siddharthac6/json-web-token-jwt-the-right-way-of-implementing-with-node-js-65b8915d550e and it recommends using 512 bit keys saying

"Its almost impossible to make a brute force search on a 256-bit key"

But, when I look for an openssl script to generate this token, I reach this page which defaults to a 4096 bit key: https://gist.github.com/ygotthilf/baa58da5c3dd1f69fae9 with one user quoting RSA which says:

RSA claims that [...] 2048-bit keys are sufficient until 2030.

It feels like there is conflicting information. In essence, my question is what jwt algorithm and key size should I use for an enterprise application and is RS256 + 512 bit keys enough (what I switched to)? I somewhat understand the trade-off of security and speed, but I'm confused why 512 bit keys are suggested in the medium article, but not even mentioned in that github script and RSA says even 2048 bit keys may be outdated by 2030.

Thank you.

1 Answers

In cryptography and thus for signature and encryption algorithms defined by the JWS/JWE specifications, we can have two types of keys:

  • Symmetric (=shared secret)
  • Asymmetric (=public/private key pair)

The HS256 algorithm uses symmetric keys and, for this type of key, the current recommendation is to use at least 256 bits keys.

The RS256 algorithm uses asymmetric RSA key pairs. Recommended minimum size is 2048 bits.

In the blog post you mentioned we can read

« with every doubling of the RSA key length, decryption gets at least 6 times slower. »

That’s true, however in general the keys are used for a large period of time (e.g. 2 weeks) and a signature computation/verification with a 2048 bit key takes approx. 250µs.

So unless you are not in production, a RSA 512 bits key is a bad idea. You will find useful information in the Recommendation for Key Management from NIST pages 53 and 54.

Related