Framework EDI Reference. Methods and Properties
mailMessage. PrepareEnvelopedEncrypt

Encrypts the message content to Cryptographic Message Syntax (CMS) EnvelopedData format.

Syntax:

Returns:

Returns 1 if the operation is successful; otherwise returns 0 if the operation fails.

Remarks:

Encrypts the entire content -- header and body -- of the message to the EnvelopedData format.  The resulting encrypted data overwrites the existing body, and the following new set of headers replease the old set:

For alternate security settings, apply different parameters on the ediSecurity object that can be accessed using the GetSecurity method.

Example:

Dim oEdiDoc As Fredi.ediDocument
Dim oMailDocument As Fredi.mailDocument
Dim oMessage As Fredi.mailMessage
Dim oSecurity As Fredi.ediSecurity
Dim oSecurities As Fredi.ediSecurities

' Create instance of Framework EDI.
Set oEdiDoc = New Fredi.ediDocument

' Get securities.
Set oSecurities = oEdiDoc.GetSecurities

' Set the default certificate store
oSecurities.DefaultCertSystemStoreName = ksCertStoreName ' Case sensitive

' Set the default certificate store location
oSecurities.DefaultCertSystemStoreLocation = ksCertStoreLocation

' Get internet mail document object
Set oMailDocument = oEdiDoc.GetMailDocument

' Disable auto-processing so that message can be secure as is.
oMailDocument.Option(MailDocOpt_Auto) = 0

' Load the mail document
oMailDocument.Load App.Path & "\SampleMail.TXT"

' Get the message.
Set oMessage = oMailDocument.GetMessage

' Get the security, and specify certificate used to encrypt.
Set oSecurity = oMessage.GetSecurity
oSecurity.CertificateSubjectName = ksCertSubjectName

' Encrypt message.
oMessage.PrepareEnvelopedEncrypt

oMessage.Save App.Path & "\MyEnvelopedDataOutput.TXT"

MsgBox "Done"

Sample

M_PrepareEnvelopedEncrypt.zip

See Also.

RFC 2630 - Cryptographic Message Syntax.