By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,758 Members | 1,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,758 IT Pros & Developers. It's quick & easy.

CAPICOM EnvelopedData Troubles

P: n/a
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_CU RRENT_USER_STORE,
_currStoreName,CAPICOM_STORE_OPEN_MODE.CAPICOM_STO RE_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 = "jz******@dovetailinternet.com";
theMessage.From = "jz******@dovetailinternet.com";
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.CAPIC OM_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");
}
Nov 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.