Jeffery,
I already have a working version using CAPICOM but I have to use CDO to
signed the email and not system.net.mail so I have not removed the
non-managed code that I wanted to...

I guess I'll have to stick with that..
Here is the signing function that I put together..obviously does not work
but wanted to show you what I have so far:
Public Sub SignMessage_Managed(ByVal oCert As
X509Certificates.X509Certificate2)
Const sFuncName As String = "SignMessage"
Try
Dim oSigner As New CmsSigner(oCert) 'Signer Cert Passed in as parameter
Dim oContentStream As IO.Stream 'Stream for Alternateview Components
Dim oContentinfo As ContentInfo 'Content info from Stream
Dim oEncoder As New System.Text.ASCIIEncoding 'Encoder
'Setting the Sender infom from the Cert
moMailMsg.From = New
MailAddress(oSigner.Certificate.GetNameInfo(X509Certificates.X509NameType.EmailName, False))
moMailMsg.ReplyTo = New
MailAddress(oSigner.Certificate.GetNameInfo(X509Certificates.X509NameType.EmailName, False))
moMailMsg.Sender = New
MailAddress(oSigner.Certificate.GetNameInfo(X509Certificates.X509NameType.EmailName, False))
'If there is an alternate view (embedded images etc) we'll extract to
a stream and turn into a contentinfo object
If moMailMsg.AlternateViews.Count > 0 Then
Dim oAlternateView As AlternateView = moMailMsg.AlternateViews(0)
With oAlternateView
oContentStream = .ContentStream
End With
Dim oContentBytes(oContentStream.Length) As Byte
oContentStream.Read(oContentBytes, 0, oContentStream.Length)
oContentStream.Close()
oContentinfo = New ContentInfo(oContentBytes)
Else
Dim oContentBytes As Byte() = oEncoder.GetBytes(moMailMsg.Body)
oContentinfo = New ContentInfo(oContentBytes)
End If
'Signing the Data
Dim oSignedData As New SignedCms(oContentinfo)
oSignedData.ComputeSignature(oSigner)
Dim oEncodedBytes As Byte() = oSignedData.Encode()
Dim sSignedContent As String = oEncoder.GetString(oEncodedBytes)
'Trying to rebuild the alternate View from the encoded stream.
'This is where it goes wrong...
Dim oNewAlternateView As AlternateView =
AlternateView.CreateAlternateViewFromString(sSignedContent,
System.Text.Encoding.UTF8, MediaTypeNames.Text.Html)
moMailMsg.AlternateViews.RemoveAt(0) 'Removing the existing Alternate
view
moMailMsg.AlternateViews.Add(oNewAlternateView) 'adding the signed
version.
Catch ex As Exception
ex.Source = sClassName & "::" & sFuncName
Throw New Exception(ex.Message, ex.InnerException)
Finally
End Try
End Sub
Product Engineering provided me with a patched version of the CAPICOM dll a
few years ago when I firsted moved the code to .Net. I may raise this as an
issue through the same channels and see if we can get something working...
Thanks for your help Jeffery..
"Jeffrey Tan[MSFT]" said:
Hi Jason,
Thanks for your feedback!
If I do not misunderstand you, I think you have managed to use managed code
to sign the email, the current problem is how to place it in the correct
email format that Outlook can recognize.
Can you show me some details regarding how you use managed code to do the
S/MIME digital signing? Based on the consult feedback, there is no build-in
support for this in .Net:
Your choices are ¨C
1. Use a third party component, there are plenty out there, I¡¯ve not
evaluated any of them so I can¡¯t recommend one.
2. You can use COM Interop with CAPICOM to produce digitally
signed/encrypted e-mails from .NET
Regarding the latter option, you have to write an S/MIME class that
implements the S/MIME and MIME RFCs. So it's the harder option, but means
you're free of third party dependencies and licensing, all you need is
CAPICOM.
Do you think the option2 is suitable for you? Please feel free to tell me,
thanks!
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.