【发布时间】:2020-09-04 09:08:14
【问题描述】:
我正在编写一个涉及通过网络发送公钥的 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 from cryptography.hazmat.backends import default_backend 获取默认后端并将
default_backend()(请注意,您必须将其作为方法调用!)作为参数。您也可以升级到 3.1+。
标签: python serialization cryptography deserialization public-key-encryption