python - 使用 python 的加密模块反序列化公钥
问题描述
我正在编写一个涉及通过网络发送公钥的 python 脚本。我正在使用 < https://cryptography.io/en/latest/hazmat/primitives/asymmetric/serialization/。>
public_key = self.node.public_key
pem = public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo
)
deserialized_key = load_pem_public_key(pem)
我得到错误:
TypeError: load_pem_public_key() missing 1 required positional argument: 'backend'
因此,我无法反序列化密钥 - 我很困惑,因为根据文档, load_pem_public_key() 需要 1 个必需参数(数据)和 1 个可选参数(后端)。
解决方案
看起来你在需要参数的cryptography==3.0
地方使用或更低https://github.com/pyca/cryptography/blob/3.0/src/cryptography/hazmat/primitives/serialization/base.py#L19backend
撞到cryptography==3.1
或放东西到backend
arg
推荐阅读
- python - 根据列值的条件从主数据框创建新的数据框(不使用.ix)
- python - Tkinter:无法让网格几何管理器使用框架
- django - django modelmanager 查询集不返回页面
- c - Android NDK SIGSEGV 致命信号 11,代码 2 (SEGV_ACCERR)
- python - 使用 pandas 对象计算公式
- javascript - ReactJS在运行函数后清除textarea值
- python - Python中函数的奇怪热编码问题
- flutter - 如何在模型类型列表列表中的零位置插入默认值
在颤动的下拉按钮中显示 - python - 如何使用 XML 对 Django Rest Framework 端点进行单元测试?
- python - 处理图像时难以重塑 numpy 数组