title: Creating and saving CMS / PKCS#7 objects in Python
body: <p>I need to be able to generate, save and read CMS / PKCS#7 data in Python. It seems that it can be done using <code>asn1crypto</code> library, but I am having a hard time finding functions that would allow me to save the data to the disk (in PEM/DER format). There is a <a href="https://github.com/wbond/asn1crypto/blob/master/tests/test_cms.py" rel="nofollow noreferrer">testbench at asn1crypto/tests/test_cms.py</a>, but it only shows how to read CMS / PKCS#7 data from the files and store it into corresponding asn1crypto.cms objects. I was not able to find a manual or even a list of asn1crypto.cms functions (methods). </p>
  
  <p>For now, I am able to generate all the necessary pieces such as a signature, encrypted data, symmetric key, etc, so what I need to do is to find a way to fuse them together into CMS / PKCS#7 compatible file formats. Basically, I am looking for an equivalent Python flow for the shell's <code>openssl cms</code> and <code>openssl engine</code> capabilities. A simple Python example showing how to create and save a CMS object (e.g., SignedData, EnvelopedData, etc) would go a long way.  </p>