def encrypt_message(data_to_encrypt, enc_alg, encryption_cert):
    """Function encrypts data and returns the generated ASN.1

    :param data_to_encrypt: A byte string of the data to be encrypted
    
    :param enc_alg: The algorithm to be used for encrypting the data
    
    :param encryption_cert: The certificate to be used for encrypting the data

    :return: A CMS ASN.1 byte string of the encrypted data.    
    """

    enc_alg_list = enc_alg.split('_')
    cipher, key_length, mode = enc_alg_list[0], enc_alg_list[1], enc_alg_list[2]
    enc_alg_asn1, key, encrypted_content = None, None, None

    # Generate the symmetric encryption key and encrypt the message
    if cipher == 'tripledes':
        key = util.rand_bytes(int(key_length)//8)
        iv, encrypted_content = symmetric.tripledes_cbc_pkcs5_encrypt(
            key, data_to_encrypt, None)
        enc_alg_asn1 = algos.EncryptionAlgorithm({
            'algorithm': algos.EncryptionAlgorithmId('tripledes_3key'),
            'parameters': cms.OctetString(iv)
        })

    # Encrypt the key and build the ASN.1 message
    encrypted_key = asymmetric.rsa_pkcs1v15_encrypt(encryption_cert, key)

    return cms.ContentInfo({
        'content_type': cms.ContentType('enveloped_data'),
        'content': cms.EnvelopedData({
            'version': cms.CMSVersion('v0'),
            'recipient_infos': [
                cms.KeyTransRecipientInfo({
                    'version': cms.CMSVersion('v0'),
                    'rid': cms.RecipientIdentifier({
                        'issuer_and_serial_number': cms.IssuerAndSerialNumber({
                            'issuer': encryption_cert.asn1[
                                'tbs_certificate']['issuer'],
                            'serial_number': encryption_cert.asn1[
                                'tbs_certificate']['serial_number']
                        })
                    }),
                    'key_encryption_algorithm': cms.KeyEncryptionAlgorithm({
                        'algorithm': cms.KeyEncryptionAlgorithmId('rsa')
                    }),
                    'encrypted_key': cms.OctetString(encrypted_key)
                })
            ],
            'encrypted_content_info': cms.EncryptedContentInfo({
                'content_type': cms.ContentType('data'),
                'content_encryption_algorithm': enc_alg_asn1,
                'encrypted_content': encrypted_content
            })
        })
    }).dump()
Function encrypts data and returns the generated ASN.1

    :param data_to_encrypt: A byte string of the data to be encrypted
    
    :param enc_alg: The algorithm to be used for encrypting the data
    
    :param encryption_cert: The certificate to be used for encrypting the data

    :return: A CMS ASN.1 byte string of the encrypted data.