'Return a public or private OpenSSH string.  See
_fromString_PUBLIC_OPENSSH and _fromString_PRIVATE_OPENSSH for the
string formats.  If extra is present, it represents a comment for a
public key, or a passphrase for a private key.
@param extra: Comment for a public key or passphrase for a
private key
@type extra: L{bytes}
@rtype: L{bytes}'

def _toString_OPENSSH(self, extra):

    data = self.data()
    if self.isPublic():
        if (self.type() == 'EC'):
            if (not extra):
                extra = ''
            return ((self._keyObject.public_bytes(serialization.Encoding.OpenSSH, serialization.PublicFormat.OpenSSH) + '    ') + extra).strip()
        b64Data = encodebytes(self.blob()).replace('\n', '')
        if (not extra):
            extra = ''
        return ((((self.sshType() + '    ') + b64Data) + '    ') + extra).strip()
    else:
        if (self.type() == 'EC'):
            if (not extra):
                encryptor = serialization.NoEncryption()
            else:
                encryptor = serialization.BestAvailableEncryption(extra)
            return self._keyObject.private_bytes(serialization.Encoding.PEM, serialization.PrivateFormat.TraditionalOpenSSL, encryptor)
        lines = [''.join(('-----BEGIN    ', self.type().encode('ascii'), '    PRIVATE    KEY-----'))]
        if (self.type() == 'RSA'):
            (p, q) = (data['p'], data['q'])
            objData = (0, data['n'], data['e'], data['d'], q, p, (data['d'] % (q - 1)), (data['d'] % (p - 1)), data['u'])
        else:
            objData = (0, data['p'], data['q'], data['g'], data['y'], data['x'])
        asn1Sequence = univ.Sequence()
        for (index, value) in izip(itertools.count(), objData):
            asn1Sequence.setComponentByPosition(index, univ.Integer(value))
        asn1Data = berEncoder.encode(asn1Sequence)
        if extra:
            iv = randbytes.secureRandom(8)
            hexiv = ''.join([('%02X' % (ord(x),)) for x in iterbytes(iv)])
            hexiv = hexiv.encode('ascii')
            lines.append('Proc-Type:    4,ENCRYPTED')
            lines.append((('DEK-Info:    DES-EDE3-CBC,' + hexiv) + '\n'))
            ba = md5((extra + iv)).digest()
            bb = md5(((ba + extra) + iv)).digest()
            encKey = (ba + bb)[:24]
            padLen = (8 - (len(asn1Data) % 8))
            asn1Data += (chr(padLen) * padLen).encode('ascii')
            encryptor = Cipher(algorithms.TripleDES(encKey), modes.CBC(iv), backend=default_backend()).encryptor()
            asn1Data = (encryptor.update(asn1Data) + encryptor.finalize())
        b64Data = encodebytes(asn1Data).replace('\n', '')
        lines += [b64Data[i:(i + 64)] for i in range(0, len(b64Data), 64)]
        lines.append(''.join(('-----END    ', self.type().encode('ascii'), '    PRIVATE    KEY-----')))
        return '\n'.join(lines)
