1

I'm just start working with/learning jwt. To implement it I've decided to use PyJWT. Also I want RS256 algorithm.

First of all I've just run example from documentation: https://pyjwt.readthedocs.io/en/latest/usage.html

But EVEN SO I've already got the error.

import jwt
#generated through openssl rand -hex 32
private_key = b"-----BEGIN PRIVATE KEY-----\n05efe020898a93723a656d59af6c7a5ba57034885031f83be181b12f774db8b0"
public_key = b"-----BEGIN PUBLIC KEY-----\n7f2cdde8ba0c56bace4315398fb8016750a9d081e958a06443cbf56f8936cb86"
encoded = jwt.encode({"some": "payload"}, "secret", algorithm="RS256")
Exception has occurred: ValueError
Could not deserialize key data. The data may be in an incorrect format or it may be encrypted with an unsupported algorithm.

During handling of the above exception, another exception occurred:

Of course, I can use HS256, but RS256 is more preferable

Rumotameru
  • 111
  • 1
  • 8
  • 1
    you can't just create a random number and call it RSA key. An RSA key has a specific format. You can generate RSA keys online (e.g. https://travistidwell.com/jsencrypt/demo/) – jps Oct 29 '21 at 08:46

0 Answers0