首页 > 解决方案 > 使用 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 个可选参数(后端)。

标签: pythonserializationcryptographydeserializationpublic-key-encryption

解决方案


看起来你在需要参数的cryptography==3.0地方使用或更低https://github.com/pyca/cryptography/blob/3.0/src/cryptography/hazmat/primitives/serialization/base.py#L19backend

撞到cryptography==3.1或放东西到backendarg


推荐阅读