diff --git a/creatersa.py b/creatersa.py index 776b96c..d6eb3db 100644 --- a/creatersa.py +++ b/creatersa.py @@ -15,3 +15,27 @@ unencrypted_pem_private_key = private_key.private_bytes( ) unencrypted_pem_private_key.splitlines()[0] + + + +private_key_file = open("example-rsa.pem", "w") +private_key_file.write(unencrypted_pem_private_key.decode()) +private_key_file.close() + +# --- Better way of storing the key in a file: + +with open("path/to/store/key.pem", "wb") as f: + f.write(private_key.private_bytes( + encoding=serialization.Encoding.PEM, + format=serialization.PrivateFormat.TraditionalOpenSSL, + encryption_algorithm=serialization.BestAvailableEncryption(b"passphrase"), + )) + +pem_public_key = private_key.public_key().public_bytes( + encoding=serialization.Encoding.PEM, + format=serialization.PublicFormat.SubjectPublicKeyInfo +) + +public_key_file = open("example-rsa.pub", "w") +public_key_file.write(pem_public_key.decode()) +public_key_file.close() \ No newline at end of file