def dump_openssl_private_key(private_key, passphrase):
if passphrase is not None:<EOL><INDENT>if not isinstance(passphrase, str_cls):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(passphrase)<EOL>))<EOL><DEDENT>if passphrase == '<STR_LIT>':<EOL><INDENT>raise ValueError(pretty_message(<EOL>'''<STR_LIT>'''<EOL>))<EOL><DEDENT><DEDENT>is_oscrypto = isinstance(private_key, PrivateKey)<EOL>if not isinstance(private_key, keys.PrivateKeyInfo) and not is_oscrypto:<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(private_key)<EOL>))<EOL><DEDENT>if is_oscrypto:<EOL><INDENT>private_key = private_key.asn1<EOL><DEDENT>output = private_key.unwrap().dump()<EOL>headers = None<EOL>if passphrase is not None:<EOL><INDENT>iv = rand_bytes(<NUM_LIT:16>)<EOL>headers = OrderedDict()<EOL>headers['<STR_LIT>'] = '<STR_LIT>'<EOL>headers['<STR_LIT>'] = '<STR_LIT>' % binascii.hexlify(iv).decode('<STR_LIT:ascii>')<EOL>key_length = <NUM_LIT:16><EOL>passphrase_bytes = passphrase.encode('<STR_LIT:utf-8>')<EOL>key = hashlib.md5(passphrase_bytes + iv[<NUM_LIT:0>:<NUM_LIT:8>]).digest()<EOL>while key_length > len(key):<EOL><INDENT>key += hashlib.md5(key + passphrase_bytes + iv[<NUM_LIT:0>:<NUM_LIT:8>]).digest()<EOL><DEDENT>key = key[<NUM_LIT:0>:key_length]<EOL>iv, output = aes_cbc_pkcs7_encrypt(key, output, iv)<EOL><DEDENT>if private_key.algorithm == '<STR_LIT>':<EOL><INDENT>object_type = '<STR_LIT>'<EOL><DEDENT>elif private_key.algorithm == '<STR_LIT>':<EOL><INDENT>object_type = '<STR_LIT>'<EOL><DEDENT>elif private_key.algorithm == '<STR_LIT>':<EOL><INDENT>object_type = '<STR_LIT>'<EOL><DEDENT>return pem.armor(object_type, output, headers=headers)<EOL>
Serializes a private key object into a byte string of the PEM formats used
by OpenSSL. The format chosen will depend on the type of private key - RSA,
DSA or EC.

Do not use this method unless you really must interact with a system that
does not support PKCS#8 private keys. The encryption provided by PKCS#8 is
far superior to the OpenSSL formats. This is due to the fact that the
OpenSSL formats don't stretch the passphrase, making it very easy to
brute-force.

:param private_key:
    An oscrypto.asymmetric.PrivateKey or asn1crypto.keys.PrivateKeyInfo
    object

:param passphrase:
    A unicode string of the passphrase to encrypt the private key with.
    A passphrase of None will result in no encryption. A blank string will
    result in a ValueError to help ensure that the lack of passphrase is
    intentional.

:raises:
    ValueError - when a blank string is provided for the passphrase

:return:
    A byte string of the encoded and encrypted public key