def _encrypt(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 != Security.kSecAttrKeyTypeRC4 and not isinstance(iv, byte_cls):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(iv)<EOL>))<EOL><DEDENT>if cipher != Security.kSecAttrKeyTypeRC4 and not padding:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>cf_dict = None<EOL>cf_key = None<EOL>cf_data = None<EOL>cf_iv = None<EOL>sec_key = None<EOL>sec_transform = None<EOL>try:<EOL><INDENT>cf_dict = CFHelpers.cf_dictionary_from_pairs([(Security.kSecAttrKeyType, cipher)])<EOL>cf_key = CFHelpers.cf_data_from_bytes(key)<EOL>cf_data = CFHelpers.cf_data_from_bytes(data)<EOL>error_pointer = new(CoreFoundation, '<STR_LIT>')<EOL>sec_key = Security.SecKeyCreateFromData(cf_dict, cf_key, error_pointer)<EOL>handle_cf_error(error_pointer)<EOL>sec_transform = Security.SecEncryptTransformCreate(sec_key, error_pointer)<EOL>handle_cf_error(error_pointer)<EOL>if cipher != Security.kSecAttrKeyTypeRC4:<EOL><INDENT>Security.SecTransformSetAttribute(sec_transform, Security.kSecModeCBCKey, null(), error_pointer)<EOL>handle_cf_error(error_pointer)<EOL>Security.SecTransformSetAttribute(sec_transform, Security.kSecPaddingKey, padding, error_pointer)<EOL>handle_cf_error(error_pointer)<EOL>cf_iv = CFHelpers.cf_data_from_bytes(iv)<EOL>Security.SecTransformSetAttribute(sec_transform, Security.kSecIVKey, cf_iv, error_pointer)<EOL>handle_cf_error(error_pointer)<EOL><DEDENT>Security.SecTransformSetAttribute(<EOL>sec_transform,<EOL>Security.kSecTransformInputAttributeName,<EOL>cf_data,<EOL>error_pointer<EOL>)<EOL>handle_cf_error(error_pointer)<EOL>ciphertext = Security.SecTransformExecute(sec_transform, error_pointer)<EOL>handle_cf_error(error_pointer)<EOL>return CFHelpers.cf_data_to_bytes(ciphertext)<EOL><DEDENT>finally:<EOL><INDENT>if cf_dict:<EOL><INDENT>CoreFoundation.CFRelease(cf_dict)<EOL><DEDENT>if cf_key:<EOL><INDENT>CoreFoundation.CFRelease(cf_key)<EOL><DEDENT>if cf_data:<EOL><INDENT>CoreFoundation.CFRelease(cf_data)<EOL><DEDENT>if cf_iv:<EOL><INDENT>CoreFoundation.CFRelease(cf_iv)<EOL><DEDENT>if sec_key:<EOL><INDENT>CoreFoundation.CFRelease(sec_key)<EOL><DEDENT>if sec_transform:<EOL><INDENT>CoreFoundation.CFRelease(sec_transform)<EOL><DEDENT><DEDENT>
Encrypts plaintext

:param cipher:
    A kSecAttrKeyType* value that specifies the cipher to use

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

:param data:
    The plaintext - a byte string

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

:param padding:
    The padding mode to use, specified as a kSecPadding*Key value - 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 the OS crypto library

:return:
    A byte string of the ciphertext