'Return a private key object corresponding to this OpenSSH private key
string.  If the key is encrypted, passphrase MUST be provided.
Providing a passphrase for an unencrypted key is an error.
The format of an OpenSSH private key string is::
-----BEGIN <key type> PRIVATE KEY-----
[Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,<initialization value>]
<base64-encoded ASN.1 structure>
------END <key type> PRIVATE KEY------
The ASN.1 structure of a RSA key is::
(0, n, e, d, p, q)
The ASN.1 structure of a DSA key is::
(0, p, q, g, y, x)
The ASN.1 structure of a ECDSA key is::
(ECParameters, OID, NULL)
@type data: L{bytes}
@param data: The key data.
@type passphrase: L{bytes} or L{None}
@param passphrase: The passphrase the key is encrypted with, or L{None}
if it is not encrypted.
@return: A new key.
@rtype: L{twisted.conch.ssh.keys.Key}
@raises BadKeyError: if
* a passphrase is provided for an unencrypted key
* the ASN.1 encoding is incorrect
@raises EncryptedKeyError: if
* a passphrase is not provided for an encrypted key'

@classmethod
def _fromString_PRIVATE_OPENSSH(cls, data, passphrase):

    lines = data.strip().splitlines()
    kind = lines[0][11:(-17)]
    if lines[1].startswith('Proc-Type:    4,ENCRYPTED'):
        if (not passphrase):
            raise EncryptedKeyError('Passphrase    must    be    provided    for    an    encrypted    key')
        try:
            (_, cipherIVInfo) = lines[2].split('    ', 1)
            (cipher, ivdata) = cipherIVInfo.rstrip().split(',', 1)
        except ValueError:
            raise BadKeyError(('invalid    DEK-info    %r' % (lines[2],)))
        if (cipher in ('AES-128-CBC', 'AES-256-CBC')):
            algorithmClass = algorithms.AES
            keySize = int((int(cipher.split('-')[1]) / 8))
            if (len(ivdata) != 32):
                raise BadKeyError('AES    encrypted    key    with    a    bad    IV')
        elif (cipher == 'DES-EDE3-CBC'):
            algorithmClass = algorithms.TripleDES
            keySize = 24
            if (len(ivdata) != 16):
                raise BadKeyError('DES    encrypted    key    with    a    bad    IV')
        else:
            raise BadKeyError(('unknown    encryption    type    %r' % (cipher,)))
        iv = bytes(bytearray([int(ivdata[i:(i + 2)], 16) for i in range(0, len(ivdata), 2)]))
        ba = md5((passphrase + iv[:8])).digest()
        bb = md5(((ba + passphrase) + iv[:8])).digest()
        decKey = (ba + bb)[:keySize]
        b64Data = decodebytes(''.join(lines[3:(-1)]))
        decryptor = Cipher(algorithmClass(decKey), modes.CBC(iv), backend=default_backend()).decryptor()
        keyData = (decryptor.update(b64Data) + decryptor.finalize())
        removeLen = ord(keyData[(-1):])
        keyData = keyData[:(- removeLen)]
    else:
        b64Data = ''.join(lines[1:(-1)])
        keyData = decodebytes(b64Data)
    try:
        decodedKey = berDecoder.decode(keyData)[0]
    except PyAsn1Error as e:
        raise BadKeyError(('Failed    to    decode    key    (Bad    Passphrase?):    %s' % (e,)))
    if (kind == 'EC'):
        return cls(load_pem_private_key(data, passphrase, default_backend()))
    if (kind == 'RSA'):
        if (len(decodedKey) == 2):
            decodedKey = decodedKey[0]
        if (len(decodedKey) < 6):
            raise BadKeyError('RSA    key    failed    to    decode    properly')
        (n, e, d, p, q, dmp1, dmq1, iqmp) = [long(value) for value in decodedKey[1:9]]
        if (p > q):
            (p, q) = (q, p)
        return cls(rsa.RSAPrivateNumbers(p=p, q=q, d=d, dmp1=dmp1, dmq1=dmq1, iqmp=iqmp, public_numbers=rsa.RSAPublicNumbers(e=e, n=n)).private_key(default_backend()))
    elif (kind == 'DSA'):
        (p, q, g, y, x) = [long(value) for value in decodedKey[1:6]]
        if (len(decodedKey) < 6):
            raise BadKeyError('DSA    key    failed    to    decode    properly')
        return cls(dsa.DSAPrivateNumbers(x=x, public_numbers=dsa.DSAPublicNumbers(y=y, parameter_numbers=dsa.DSAParameterNumbers(p=p, q=q, g=g))).private_key(backend=default_backend()))
    else:
        raise BadKeyError(('unknown    key    type    %s' % (kind,)))
