473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Digital Signature (CDO and CryptoAPI)

I Have a .NET program sending mails using CDOEX.

These mail I need to sign. I god a tip that i shoud use CAPICOM. That worked
fine sending a mail with signature.

BUT the problem is that I have to type the password for my certificate every
time my program signs a mail :o(

My program is a windows service running on a server so typing passwords is
bad.

Then I got a new tip, I should use CryptoAPI instead of CAPICOM.

I think i have solved the CryptoAPI mystic and got my certificate, signed my
body of the mail and got the hash for it. But I don't know how to get my
signed code into the mail?

The code looks like this, and gives this error when the outlook client
reseive the mail:

Error: Can't open this item. Your Digital ID name can not be found by the
underlying security system.

This takes a byte array that I send from my CryptoAPI code.
Code:

private void SendMail(byte[] byteSignature)
{
CDO.IBodyPart oBodyPart;
ADODB.Fields cFields;
ADODB.Stream oStream;

// set sender, recipient, and subject.
oMessage = new CDO.Message();

oMessage.To = "My*****@Domain.dk";
oMessage.Subject = "Test Mail";
oMessage.Fields["urn:schemas:mailheader:date"].Value = DateTime.UtcNow;
oMessage.Fields.Update();

oMessage.From = "kh@evision.as";

oBodyPart = oMessage.BodyPart.AddBodyPart(1);
cFields = oBodyPart.Fields;

cFields["urn:schemas:mailheader:content-type"].Value =
CDO.CdoContentTypeValues.cdoTextPlain;
cFields.Update();

oStream = oBodyPart.GetDecodedContentStream();
oStream.WriteText("Hello this is some test text",0);
oStream.Flush();

//
//
// Start the new message
//
//
CDO.Message oSignedMsg = new CDO.Message();
CDO.IBodyPart oBodyPart2;
ADODB.Fields cFields2;
ADODB.Stream oStream2;

oSignedMsg.From = "My*****@domain.dk";

// this is to be a clear text signed message so we need to copy the
interesting
// parts (sender, recipient, and subject) into the new header
oSignedMsg.To = oMessage.To;
oSignedMsg.CC = oMessage.CC;
oSignedMsg.Subject = oMessage.Subject;

oBodyPart2 = oSignedMsg.BodyPart.AddBodyPart(1);
cFields2 = oBodyPart2.Fields;

cFields2["urn:schemas:mailheader:content-type"].Value =
oMessage.BodyPart.BodyParts[1].Fields["urn:schemas:mailheader:content-type"].Value;
cFields2.Update();

// Attach the signature and let CDO base64 encode it
oBodyPart2 = oSignedMsg.BodyPart.AddBodyPart(1);
cFields2 = oBodyPart2.Fields;
oBodyPart2.Fields["urn:schemas:mailheader:content-type"].Value =
"application/x-pkcs7-signature\rName = " + '\u0022' + "smime.p7s" + '\u0022'
+ "";

oBodyPart2.Fields["urn:schemas:mailheader:content-transfer-encoding"].Value =
"base64";
oBodyPart2.Fields["urn:schemas:mailheader:content-disposition"].Value =
"attachment;\rFileName=" + '\u0022' + "smime.p7s" + '\u0022' + "";
cFields2.Update();
//
oStream2 = oBodyPart2.GetDecodedContentStream();
oStream2.Type = ADODB.StreamTypeEnum.adTypeBinary;
oStream2.Write (byteSignature);
oStream2.Flush();

// Set the messages content type, this needs to be done last to ensure
it is not changed when we add the BodyParts

oSignedMsg.Fields["urn:schemas:mailheader:content-type"].Value =
"multipart/signed;\rprotocol=" + '\u0022' + "application/x-pkcs7-signature" +
'\u0022' + ";\rmicalg=SHA1;";

oSignedMsg.Fields.Update();

oMessage = oSignedMsg;
oMessage.Send();
}
Jul 21 '05 #1
0 1877

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Kim | last post by:
I have a .NET service sending mails using CDOEX. These mails I need to sign. I got a tip that I should use CAPICOM. That worked fine sending a mail with signature. BUT the problem is that I...
7
by: Guangxi Wu | last post by:
Hi all, Happy New Year. I am using SignedXML and an X509 certificate to digitally sign a SOAP message body and put the signature in the SOAP header for a B2B business application. Can you...
5
by: John Campbell | last post by:
Hi everyone I've been doing my best to understand the specifics of implimentating XML Digital Signatures, but I seem to be missing a fundamental concept. Let me start with a description of the...
0
by: no game | last post by:
I have a problem with signature using RSACryptoServiceProvider I use signature=privKey.SignData(byteData, new MD5CryptoServiceProvide), and get a byte array of signature. The other...
2
by: Martin Høst Normark | last post by:
Hi everyone Has anyone got the least experience in integrating the Digital Signature with an ASP.NET Web Application? Here in Denmark, as I supose in many other countries, they're promoting...
1
by: claudia_usa | last post by:
Hello, Does anyone know how to include the signature field when creating PDF crystal reports with VB.net? Our intension is to allow the user to generate the report with their digital signature...
0
by: Kim HM | last post by:
I Have a .NET program sending mails using CDOEX. These mail I need to sign. I god a tip that i shoud use CAPICOM. That worked fine sending a mail with signature. BUT the problem is that I have...
0
by: krazysmile | last post by:
Hey everyone. Im coming from this thread: http://www.thescripts.com/forum/thread117164.html Cant reply there, so im making a new one, also the last post is very old. Im trying to sing an email...
3
by: tmoloy | last post by:
I am using RFID tags to store some data which will then be read by a 3rd party. I need to include a digital signature (or some variation) along with the data so that the 3rd party can verify the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.