title: CMS Signature X509 Certificate with Bouncy Castle
body: <p>I need to translate this .Net code to BouncyCastle code because i need to use in mono</p>
  
  <pre><code>X509Certificate2 certFirmante = LoadCertFromFile("sign.p12");
  ContentInfo infoContenido = new ContentInfo(argBytesMsg);
  
  SignedCms cmsFirmado = new SignedCms(infoContenido);
  CmsSigner cmsFirmante = new CmsSigner(argCertFirmante);
  
  cmsFirmante.IncludeOption = X509IncludeOption.EndCertOnly;
  
  cmsFirmado.ComputeSignature(cmsFirmante, true);
  
  return cmsFirmado.Encode();
  </code></pre>
  
  <p>I try with this code but the signed data is not the same</p>
  
  <pre><code>CmsSignedDataGenerator gen = new CmsSignedDataGenerator();
  CmsEnvelopedDataStreamGenerator dataGenerator = new CmsEnvelopedDataStreamGenerator();
  
  
  dataGenerator.AddKeyTransRecipient(cert);
  
  // Make the output stream
  MemoryStream outStream = new MemoryStream();
  // Sign the stream
  Stream cryptoStream = dataGenerator.Open(outStream, CmsEnvelopedGenerator.Aes128Cbc);
  BinaryWriter binWriter = new BinaryWriter(cryptoStream);
  binWriter.Write(datos);
  
  byte[] contenido = new byte[outStream.Length];
  
  outStream.Read(contenido, 0, Convert.ToInt32(outStream.Length));
  return contenido;
  </code></pre>