VB.NET Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript



VB.NET Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML to XML
HTTP
IMAP
Encryption
MHT / HTML Email
PFX
RSA Encryption
S/MIME
Socket
Spider
Tar Archive
Upload
XML
XMP
Zip Compression
Misc

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Byte Array
VB.NET FTPS
System.IO

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

Encrypting and Decrypting MIME

Example code showing how to encrypt and decrypt MIME.

        Dim success As Boolean

        ' Create S/MIME encrypted MIME and decrypt using a digital certificate.
        Dim mime As New Chilkat.Mime()
        mime.UnlockComponent("anything for 30-day trial")

        ' Create a simple MIME message with 2 header fields and a plain-text body.
        mime.AddHeaderField("field1", "value1")
        mime.AddHeaderField("field2", "value2")
        mime.SetBodyFromPlainText("This is a plain-text body")

        TextBox1.Text = mime.GetMime()
        ' The text box will display this:
        ' field1: value1
        ' field2: value2
        ' content-type: text/plain;
        '         charset = "us-ascii"
        ' content-transfer-encoding: 7bit
        ' 
        ' This is a plain-text body

        ' Load a certificate from a .cer file.
        Dim cert As New Chilkat.Cert()
        success = cert.LoadFromFile("tagtooga.cer")
        If (Not success) Then
            MsgBox(cert.LastErrorText)
            Exit Sub
        End If

        success = mime.Encrypt(cert)
        If (Not success) Then
            MsgBox(mime.LastErrorText)
            Exit Sub
        End If

        ' Show the encrypted MIME
        TextBox2.Text = mime.GetMime()

        ' The text box will display this:
        ' field1: value1
        ' field2: value2
        ' content-disposition: attachment;
        '         filename = "smime.p7m"
        '         content-transfer-encoding : base64
        ' content-type: application/x-pkcs7-mime;
        '         Name = "smime.p7m"
        ' 
        '         MIIB5wYJKoZIhvcNAQcDoIIB2DCCAdQCAQAxggERMIIBDQIBADB2MGIxCzAJBgNVBAYTAlpB
        ' (The remainder of the MIME is nothing more than base64 data...)

        ' To decrypt:
        success = mime.UnwrapSecurity()
        If (Not success) Then
            MsgBox(mime.LastErrorText)
            Exit Sub
        End If

        TextBox3.Text = mime.GetMime()
        ' The result is this:
        ' field1: value1
        ' field2: value2
        ' content-type: text/plain;
        '         charset = "us-ascii"
        ' content-transfer-encoding: 7bit
        ' X-NumPartsEncrypted: 1
        ' X-Decrypted : yes
        ' 
        ' This is a plain-text body

        ' If we do not want the X-NumPartsEncrypted and X-Decrypted fields added,
        ' set mime.UnwrapExtras = false
        Dim mime2 As New Chilkat.Mime()
        mime2.UnwrapExtras = False
        mime2.AddHeaderField("field1", "value1")
        mime2.AddHeaderField("field2", "value2")
        mime2.SetBodyFromPlainText("This is a plain-text body")
        mime2.Encrypt(cert)
        mime2.UnwrapSecurity()
        TextBox3.Text = mime2.GetMime()
        ' We now have the original MIME...




 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2007 Chilkat Software, Inc. All Rights Reserved.

Mail Component · XML Parser