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).
from cryptography.hazmat.backends import default_backend
and passdefault_backend()
(note that you must invoke it as a method!) as the argument. You can also upgrade to 3.1+. – Egesta