Add helper for writing private keys to disk
This commit is contained in:
@ -104,6 +104,20 @@ def generate_pem(private_key: rsa.RSAPrivateKey) -> str:
|
||||
return pem.decode()
|
||||
|
||||
|
||||
def write_private_key(private_key: rsa.RSAPrivateKey, filename: Path) -> None:
|
||||
"""Write private key to disk."""
|
||||
encryption_algorithm = serialization.NoEncryption()
|
||||
with open(filename, "wb") as f:
|
||||
pem = private_key.private_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PrivateFormat.OpenSSH,
|
||||
encryption_algorithm=encryption_algorithm,
|
||||
)
|
||||
lines = f.write(pem)
|
||||
LOG.debug("Wrote %s lines", lines)
|
||||
f.flush()
|
||||
|
||||
|
||||
def create_private_rsa_key(filename: Path, password: str | None = None) -> None:
|
||||
"""Create an RSA Private key at the given path.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user