def _decrypt(cipher, key, data, iv, padding):
if not isinstance(key, byte_cls):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(key)<EOL>))<EOL><DEDENT>if not isinstance(data, byte_cls):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(data)<EOL>))<EOL><DEDENT>if cipher != '<STR_LIT>' and not isinstance(iv, byte_cls):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(iv)<EOL>))<EOL><DEDENT>if cipher != '<STR_LIT>' and padding is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>evp_cipher_ctx = None<EOL>try:<EOL><INDENT>evp_cipher_ctx = libcrypto.EVP_CIPHER_CTX_new()<EOL>if is_null(evp_cipher_ctx):<EOL><INDENT>handle_openssl_error(<NUM_LIT:0>)<EOL><DEDENT>evp_cipher, buffer_size = _setup_evp_encrypt_decrypt(cipher, data)<EOL>if iv is None:<EOL><INDENT>iv = null()<EOL><DEDENT>if cipher in set(['<STR_LIT>', '<STR_LIT>']):<EOL><INDENT>res = libcrypto.EVP_DecryptInit_ex(evp_cipher_ctx, evp_cipher, null(), null(), null())<EOL>handle_openssl_error(res)<EOL>res = libcrypto.EVP_CIPHER_CTX_set_key_length(evp_cipher_ctx, len(key))<EOL>handle_openssl_error(res)<EOL>if cipher == '<STR_LIT>':<EOL><INDENT>res = libcrypto.EVP_CIPHER_CTX_ctrl(<EOL>evp_cipher_ctx,<EOL>LibcryptoConst.EVP_CTRL_SET_RC2_KEY_BITS,<EOL>len(key) * <NUM_LIT:8>,<EOL>null()<EOL>)<EOL>handle_openssl_error(res)<EOL><DEDENT>evp_cipher = null()<EOL><DEDENT>res = libcrypto.EVP_DecryptInit_ex(evp_cipher_ctx, evp_cipher, null(), key, iv)<EOL>handle_openssl_error(res)<EOL>if padding is not None:<EOL><INDENT>res = libcrypto.EVP_CIPHER_CTX_set_padding(evp_cipher_ctx, int(padding))<EOL>handle_openssl_error(res)<EOL><DEDENT>buffer = buffer_from_bytes(buffer_size)<EOL>output_length = new(libcrypto, '<STR_LIT>')<EOL>res = libcrypto.EVP_DecryptUpdate(evp_cipher_ctx, buffer, output_length, data, len(data))<EOL>handle_openssl_error(res)<EOL>output = bytes_from_buffer(buffer, deref(output_length))<EOL>res = libcrypto.EVP_DecryptFinal_ex(evp_cipher_ctx, buffer, output_length)<EOL>handle_openssl_error(res)<EOL>output += bytes_from_buffer(buffer, deref(output_length))<EOL>return output<EOL><DEDENT>finally:<EOL><INDENT>if evp_cipher_ctx:<EOL><INDENT>libcrypto.EVP_CIPHER_CTX_free(evp_cipher_ctx)<EOL><DEDENT><DEDENT>
Decrypts AES/RC4/RC2/3DES/DES ciphertext

:param cipher:
    A unicode string of "aes128", "aes192", "aes256", "des",
    "tripledes_2key", "tripledes_3key", "rc2", "rc4"

:param key:
    The encryption key - a byte string 5-32 bytes long

:param data:
    The ciphertext - a byte string

:param iv:
    The initialization vector - a byte string - unused for RC4

:param padding:
    Boolean, if padding should be used - unused for RC4

:raises:
    ValueError - when any of the parameters contain an invalid value
    TypeError - when any of the parameters are of the wrong type
    OSError - when an error is returned by OpenSSL

:return:
    A byte string of the plaintext