Open stevendesu opened 4 years ago
Putting aside that the JWA specification requires that
A key of size 2048 bits or larger MUST be used with this algorithm.
Technically you can use keys of smaller bit sizes but it's not a blank check. Following are observed minimal bit sizes that OpenSSL will allow you to sign with.
RS256: 512 RS384: 624 RS512: 752 PS256: 528 PS384: 784 PS512: 1040
Nevertheless, you shouldn't - use at least 2048
There may be nothing weird or wrong about this and I just don't understand the underlying algorithms, but my understanding did not match up to the behavior I experienced.
From my understanding, keys as short at 512 bits should be acceptable when writing a JSON Web Token. However I've found experimentally then when signing tokens using the
PS512
algorithm, if I create a public/private key pair with a length less than 1034 bits then I get the error in the title.I'm generating my key like so:
I then utilize the key like so:
This is throwing the following error:
If I set the modulus length to 1034 or greater, or if I change the algorithm to
RS512
orPS256
, the error goes away.I don't understand the internals of the various algorithms well enough to understand why this is the case. I had hoped to utilize a very short key in development (512 bits) and a very large key in production (4096 bits) - but when I ran into this I just grew more and more confused.
I'm posting here because the last (non-internal) line of the stack trace pointed to
jwa
, but this could very well be an issue withjws
,jsonwebtoken
, or even with NodeJS itself