def load_private_key(source, password=None):
if isinstance(source, keys.PrivateKeyInfo):<EOL><INDENT>private_object = source<EOL><DEDENT>else:<EOL><INDENT>if password is not None:<EOL><INDENT>if isinstance(password, str_cls):<EOL><INDENT>password = password.encode('<STR_LIT:utf-8>')<EOL><DEDENT>if not isinstance(password, byte_cls):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(password)<EOL>))<EOL><DEDENT><DEDENT>if isinstance(source, str_cls):<EOL><INDENT>with open(source, '<STR_LIT:rb>') as f:<EOL><INDENT>source = f.read()<EOL><DEDENT><DEDENT>elif not isinstance(source, byte_cls):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(source)<EOL>))<EOL><DEDENT>private_object = parse_private(source, password)<EOL><DEDENT>return _load_key(private_object)<EOL>
Loads a private key into a PrivateKey object

:param source:
    A byte string of file contents, a unicode string filename or an
    asn1crypto.keys.PrivateKeyInfo object

:param password:
    A byte or unicode string to decrypt the private key file. Unicode
    strings will be encoded using UTF-8. Not used is the source is a
    PrivateKeyInfo object.

:raises:
    ValueError - when any of the parameters contain an invalid value
    TypeError - when any of the parameters are of the wrong type
    oscrypto.errors.AsymmetricKeyError - when the private key is incompatible with the OS crypto library
    OSError - when an error is returned by the OS crypto library

:return:
    A PrivateKey object