load_keyfile

classmethod KeyManager.load_keyfile(filename: Union[str, bytes], password: Union[str, bytes] = None)[source]

Returns an instance of KeyManager using a public/private key loaded from disk, instead of from string/bytes key data.

Example:

>>> km = KeyManager.load_keyfile('id_rsa')
>>> d = km.encrypt('hello world')
>>> km.decrypt(d)
b'hello world'
Parameters
  • filename (str|bytes) – The file location where the key is stored

  • password (str|bytes) – If the key is encrypted, specify the password to decrypt it

Raises
  • InvalidFormat – When the key could not be identified, is not supported, or is corrupted

  • FileNotFoundError – The given filename couldn’t be found.

Return KeyManager cls

An instance of KeyManager (or child class) initialised with the key