Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deserializing public key with python's cryptography module

I am writing a python script that involves sending a public key over a network. I am using <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)

I get the error:

TypeError: load_pem_public_key() missing 1 required positional argument: 'backend'

I am therefore unable to deserialize the key - I am confused because according to the documentation, load_pem_public_key() takes 1 required argument (data) and 1 optional argument (backend).

like image 671
walter_dane Avatar asked Sep 04 '20 09:09

walter_dane


1 Answers

Looks like you use cryptography==3.0 or lower where backend argument is required https://github.com/pyca/cryptography/blob/3.0/src/cryptography/hazmat/primitives/serialization/base.py#L19

Bump to cryptography==3.1 or put something to backend arg

like image 113
Anton Perepelitcyn Avatar answered Sep 30 '22 01:09

Anton Perepelitcyn