output_keypair

classmethod KeyManager.output_keypair(priv: Union[str, _io.BufferedWriter], pub: Union[str, _io.TextIOWrapper], *args, **kwargs) → Tuple[bytes, bytes][source]

Similar to generate_keypair() - except this also writes the private key and public key to the file locations and/or byte streams specified in the first two arguments (priv and pub)

Example

Generate a 4096-bit RSA key pair, and output the private key to the file id_rsa , and the public key to id_rsa.pub.

The generated keypair is also returned as a tuple pair (bytes) containing the private and public key:

>>> priv, pub = KeyManager.output_keypair('id_rsa', 'id_rsa.pub', alg='rsa', key_size=4096)
Parameters
  • priv (str|BufferedWriter) – File location to save private key, or writable byte stream

  • pub (str|BufferedWriter) – File location to save public key, or writable byte stream

  • args – All additional args are forwarded to generate_keypair()

  • kwargs – All kwargs are forwarded to generate_keypair()