SMIME Capabilites and Encryption Key Preference RRS feed

  • Question


    How do I add the additional authentication attributes in my signed certificate i.e SIMIE Capabilites and Encryption Key Preference, Encryption Certificate that I want to automatically email. I use C# and have attached the code below.

    I managed to add SigningTime but am not able to add SIMIE Capabilites and Encryption Key Preference, Encryption Certificate.

    I have a couple of questions in the code comments ..


    Please help.






    X509Certificate2 SignCert = new X509Certificate2("myPersonal.pfx", "p");

    X509Certificate2 EncryptCert = new X509Certificate2("publicKey.cer", "");

    StringBuilder Message = new StringBuilder();

    Oid oid = EncryptCert.SignatureAlgorithm;

    Message.AppendLine("Content-Type: text/plain; charset=\"iso-8859-1\"");

    Message.AppendLine("Content-Transfer-Encoding: 7bit");


    Message.AppendLine("plain test from console");



    MailMessage Msg = new MailMessage();

    Msg.To.Add(new MailAddress("c@c.com"));

    Msg.From = new MailAddress("x@x.com");

    Msg.Bcc.Add(new MailAddress("y@y.com"));

    Msg.Subject = "from C# code";



    byte[] BodyBytes = Encoding.ASCII.GetBytes(Message.ToString());

    EnvelopedCms ECms = new EnvelopedCms(new ContentInfo(BodyBytes));

    CmsRecipient Recipient = new CmsRecipient(

    SubjectIdentifierType.SubjectKeyIdentifier, EncryptCert);


    byte[] EncryptedBytes = ECms.Encode();


    SignedCms Cms = new SignedCms(new ContentInfo(EncryptedBytes));

    CmsSigner Signer = new CmsSigner

    (SubjectIdentifierType.SubjectKeyIdentifier, SignCert);

    Pkcs9SigningTime time = new Pkcs9SigningTime(); //managed to do the time



    //Are these these ones used for assigning SMIME Capabilites? If so how do I do that?

    CryptographicAttributeObject obj = new CryptographicAttributeObject(new Oid("1.2.840.113549.3.7"));

    Oid o2 = new Oid("1.2.840.113549.3.2");

    CryptographicAttributeObject cao = new CryptographicAttributeObject(o2);

    //How do I add encryption Key Preference, and Encryption Certificate...





    byte[] SignedBytes = Cms.Encode();


    MemoryStream ms1 = new MemoryStream(SignedBytes);

    AlternateView av1 = new AlternateView(ms1,

    "application/x-pkcs7-mime; smime-type=signed-data;name=smime.p7m; content-transfer-encoding=Base64; content-disposition=attachment; fileName=smime.p7m;");


    SmtpClient smtp = new SmtpClient("myserver");

    smtp.Credentials = new NetworkCredential("myname", "myPass");

    smtp.UseDefaultCredentials = true;


    Friday, November 16, 2007 11:34 AM