CAPICOM EnvelopedData Troubles

G

Guest

I am trying to use the CAPICOM Package to Send Secure Emails, however, I am
having a bit of trouble in getting it to work. I am able to get the proper
certificate, and seemingly encode the 'EnvelopedData' correctly, but when
attempting to open the sent message in Outlook I receive a: "Can't open this
item. Your Digital ID name can not be found by the underlying security
system." Error. I am unsure what this means exactly as it is not something I
was able to query with helpful results on Google, so I was wondering if
someone else had this issue, and knew how to resolve it.

If anyone has a good example of this process in action I would very much
appreciate a good example, so that I can perhaps see my error(s).

NOTE: I was able to Encrypt and send Messages using ChilkatDotNet so I would
assume i'm just overlooking some step of the process.

Since I find it very likely I'm doing something incorrect somewhere along
the encryption process, I have attached my source below. Any help would be
greatly appreciated:


//CLASS VARIABLES

static private String _currStoreName = "My";
static StoreClass _oCurrStore;

private System.Web.Mail.MailMessage theMessage;

private Certificates oCerts;
private Certificate oCert;

private EnvelopedData encryptedMessage;


//SOURCE CODE

private void btnSubmit_Click(object sender, System.EventArgs e)
{

_oCurrStore = new StoreClass();
_oCurrStore.Open(CAPICOM_STORE_LOCATION.CAPICOM_CURRENT_USER_STORE,
_currStoreName,CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_EXISTING_ONLY |
CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);

oCerts = (Certificates)_oCurrStore.Certificates;

foreach(Certificate cert in oCerts)
{
oCert = cert;
}

theMessage = new System.Web.Mail.MailMessage();

theMessage.To = "(e-mail address removed)";
theMessage.From = "(e-mail address removed)";
theMessage.Subject = "This is the Subject";

encryptedMessage = new EnvelopedData();
encryptedMessage.Content = "Hello World!";
encryptedMessage.Recipients.Add(oCert);

Response.Write("<B>Subject Email Name: </B>" +
oCert.GetInfo(CAPICOM.CAPICOM_CERT_INFO_TYPE.CAPICOM_CERT_INFO_SUBJECT_EMAIL_NAME) + "<BR>");

string smimeMessage =
encryptedMessage.Encrypt(CAPICOM.CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64);

StreamWriter outStream = new StreamWriter("C:\\DEV\\smime.p7m", false);
outStream.WriteLine(smimeMessage);
outStream.Close();

theMessage.Attachments.Add(new
System.Web.Mail.MailAttachment("C:\\DEV\\smime.p7m"));

theMessage.Headers.Add("Content-Type",
"application/x-pkcs7-mime;smime-type=enveloped-data;");
//theMessage.Headers.Add("Content-Transfer-Encoding", "base64");
theMessage.Headers.Remove("Content-Class");

System.Web.Mail.SmtpMail.SmtpServer = "mail.dovetailinternet.com";
System.Web.Mail.SmtpMail.Send(theMessage);

File.Delete("C:\\DEV\\smime.p7m");
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top