better way of saving the key
This commit is contained in:
@@ -15,3 +15,27 @@ unencrypted_pem_private_key = private_key.private_bytes(
|
|||||||
)
|
)
|
||||||
|
|
||||||
unencrypted_pem_private_key.splitlines()[0]
|
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()
|
||||||
Reference in New Issue
Block a user