I'm starting to cryptography.
I need to generate a PKCS # 7 file with XML, an RSA private key (which is not included in the certificate is a file extension .key) and a certificate .cer extension.

For this i'm using a BouncyCastle.

Edit:

Thanks @khlr for your help but I can not solve my problem. When sending the data to the AC returns me "Invalid CMS". 
I have this code: 

```
public static byte[] FirmaBytesMensaje(byte[] argBytesMsg, X509Certificate2 argCertFirmante)
{
    try
    {
        //Add message in object ContentInfo 
        ContentInfo infoContenido = new ContentInfo(argBytesMsg);
        SignedCms cmsFirmado = new SignedCms(infoContenido);

        CmsSigner cmsFirmante = new CmsSigner(argCertFirmante);
        cmsFirmante.IncludeOption = X509IncludeOption.EndCertOnly;

        // Sign message PKCS #7 
        cmsFirmado.ComputeSignature(cmsFirmante);

        // Encodeo el mensaje PKCS #7. 
        return cmsFirmado.Encode();
    }
    catch (Exception excepcionAlFirmar)
    {
        throw new Exception("***Error: " + excepcionAlFirmar.Message);
    }
}

```

Signing on PKCS # 7 but this makes with a "PFX" certificate, that is, that contains the private key in a ".pfx" file. 
When I use the OpenSSL command:

```
openssl smime -sign -signer cert.crt -inkey private.key -out file.xml.cms -in file.xml -outform PEM -nodetach

```

The AC responds well.
How I can do this with BouncyCastle and cer and key files? I am going crazy! :-(