1

我刚刚开始使用/学习 jwt。为了实现它,我决定使用 PyJWT。我也想要RS256算法。

首先,我刚刚从文档中运行示例:https ://pyjwt.readthedocs.io/en/latest/usage.html

但即使如此,我已经得到了错误。

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:

当然,我可以使用HS256,但RS256更可取

4

0 回答 0