load_key

classmethod KeyManager.load_key(data: Union[str, bytes], password: bytes = None) → Tuple[Union[cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization, cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization, cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey, cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey, cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey, cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey], str][source]

Load a private/public key from a string or bytes data containing the key in some format, such as PEM or OpenSSH. Use load_keyfile() to load a key from a file + auto-instantiate KeyManager with it.

Example:

>>> key = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG3v6guHpI/j7AIl3F/EWMSReX8fH8MOSq1bC3ZuEjjC'
>>> KeyManager.load_key(key)
(<cryptography.hazmat.backends.openssl.ed25519._Ed25519PublicKey object at 0x7fa118289ba8>, 'public')
Parameters
  • data (str|bytes) – The public/private key data, as a string or bytes

  • password (str|bytes) – If your key data is encrypted, pass the password in this argument to decrypt it.

Raises

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

Return tuple key_data

A tuple containing an instance of the key, and a string public or private Example: (<_Ed25519PublicKey object>, 'public')