python - pyjwt编码问题(RS256算法)
问题描述
我刚刚开始使用/学习 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更可取
解决方案
推荐阅读
- c++ - 查找存在于第一个数组中而不存在于第二个数组中的元素
- c++ - 将泛型对象传递给 Rust 并在使用后传回 C++ 进行销毁
- java - 从文本文件中解析一行并访问括号内的值
- php - 将laravel默认注册重定向到以前的url或页面
- reactjs - 在 NextJS 中,我们收到错误“React Component as default export in”,但它是针对我想要在目录中的文件
- c++ - 无法为 X.radio 创建中等可视化,因为未找到网络节点可视化 - Omnet++
- javascript - 将php数组变量传递给javascript以获取传单地图
- python - 使用 strptime() 将数据转换为 datetime 对象会产生各种错误
- reactjs - 在 React 中,尝试刷新并停留在同一页面上,但状态不会按预期更新
- json - 如何将模型值作为参数或模型从视图传递给 Javascript,然后传递给控制器方法