def _bcrypt_encrypt(certificate_or_public_key, data, rsa_oaep_padding=False):
flags = BcryptConst.BCRYPT_PAD_PKCS1<EOL>if rsa_oaep_padding is True:<EOL><INDENT>flags = BcryptConst.BCRYPT_PAD_OAEP<EOL>padding_info_struct_pointer = struct(bcrypt, '<STR_LIT>')<EOL>padding_info_struct = unwrap(padding_info_struct_pointer)<EOL>hash_buffer = buffer_from_unicode(BcryptConst.BCRYPT_SHA1_ALGORITHM)<EOL>padding_info_struct.pszAlgId = cast(bcrypt, '<STR_LIT>', hash_buffer)<EOL>padding_info_struct.pbLabel = null()<EOL>padding_info_struct.cbLabel = <NUM_LIT:0><EOL>padding_info = cast(bcrypt, '<STR_LIT>', padding_info_struct_pointer)<EOL><DEDENT>else:<EOL><INDENT>padding_info = null()<EOL><DEDENT>out_len = new(bcrypt, '<STR_LIT>')<EOL>res = bcrypt.BCryptEncrypt(<EOL>certificate_or_public_key.key_handle,<EOL>data,<EOL>len(data),<EOL>padding_info,<EOL>null(),<EOL><NUM_LIT:0>,<EOL>null(),<EOL><NUM_LIT:0>,<EOL>out_len,<EOL>flags<EOL>)<EOL>handle_error(res)<EOL>buffer_len = deref(out_len)<EOL>buffer = buffer_from_bytes(buffer_len)<EOL>res = bcrypt.BCryptEncrypt(<EOL>certificate_or_public_key.key_handle,<EOL>data,<EOL>len(data),<EOL>padding_info,<EOL>null(),<EOL><NUM_LIT:0>,<EOL>buffer,<EOL>buffer_len,<EOL>out_len,<EOL>flags<EOL>)<EOL>handle_error(res)<EOL>return bytes_from_buffer(buffer, deref(out_len))<EOL>
Encrypts a value using an RSA public key via CNG

:param certificate_or_public_key:
    A Certificate or PublicKey instance to encrypt with

:param data:
    A byte string of the data to encrypt

:param rsa_oaep_padding:
    If OAEP padding should be used instead of PKCS#1 v1.5

: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