"""Create the broker's RSA signing key once. The tool APIs get only the public key.""" from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives import serialization import pathlib k = rsa.generate_private_key(public_exponent=65537, key_size=2048) pathlib.Path("broker-private.pem").write_bytes(k.private_bytes( serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8, serialization.NoEncryption())) pathlib.Path("public.pem").write_bytes(k.public_key().public_bytes( serialization.Encoding.PEM, serialization.PublicFormat.SubjectPublicKeyInfo))