def _advapi32_encrypt(certificate_or_public_key, data, rsa_oaep_padding=False):
flags = <NUM_LIT:0><EOL>if rsa_oaep_padding:<EOL><INDENT>flags = Advapi32Const.CRYPT_OAEP<EOL><DEDENT>out_len = new(advapi32, '<STR_LIT>', len(data))<EOL>res = advapi32.CryptEncrypt(<EOL>certificate_or_public_key.ex_key_handle,<EOL>null(),<EOL>True,<EOL>flags,<EOL>null(),<EOL>out_len,<EOL><NUM_LIT:0><EOL>)<EOL>handle_error(res)<EOL>buffer_len = deref(out_len)<EOL>buffer = buffer_from_bytes(buffer_len)<EOL>write_to_buffer(buffer, data)<EOL>pointer_set(out_len, len(data))<EOL>res = advapi32.CryptEncrypt(<EOL>certificate_or_public_key.ex_key_handle,<EOL>null(),<EOL>True,<EOL>flags,<EOL>buffer,<EOL>out_len,<EOL>buffer_len<EOL>)<EOL>handle_error(res)<EOL>return bytes_from_buffer(buffer, deref(out_len))[::-<NUM_LIT:1>]<EOL>
Encrypts a value using an RSA public key via CryptoAPI

: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