title: Sign an array of bytes with X509 Certificate in .Net Core
body: <p>I want sign an array of bytes with <code>X509Certificate2</code>,</p>
  
  <p>Here are a sample for <a href="https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.pkcs.cmssigner?view=netframework-4.7" rel="nofollow noreferrer">.Net Framework 4.7</a>, but I need the same for .Net Core:</p>
  
  <pre><code> var argCertFirmante = new X509Certificate2(file, pass);
   var infoContenido = new ContentInfo(argBytesMsg);
   var cmsFirmado = new SignedCms(infoContenido);
   var cmsFirmante = new CmsSigner(argCertFirmante)
    { IncludeOption = X509IncludeOption.EndCertOnly };
   cmsFirmado.ComputeSignature(cmsFirmante, true);
   return cmsFirmado.Encode();
  </code></pre>
  
  <p>I want the equivalent to this:</p>
  
  <ul>
  <li>openssl smime -sign -signer ebookingv4.crt -inkey ebookingv4.key -out ticket.xml.cms -in ticket.xml -outform DER -nodetach</li>
  <li>openssl base64 -in ticket.xml.cms -out ticket.xml.cms.base64</li>
  </ul>
  
  <p><a href="http://www.ietf.org/rfc/rfc3852.txt" rel="nofollow noreferrer">Cryptographic Message Syntax (CMS)</a>
  With Net Core 2.0 and this nuget package i was worked fine for me:</p>
  
  <pre><code>&lt;PackageReference Include="System.Security.Cryptography.Algorithms"
  Version="4.4.0-beta-24913-01" /&gt; &lt;PackageReference
  Include="System.Security.Cryptography.Pkcs"
  Version="4.5.0-preview1-26119-06" /&gt; &lt;PackageReference
  Include="System.Security.Cryptography.X509Certificates"
  Version="4.4.0-beta-24913-01" /&gt;
  </code></pre>