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

 

 

 

 

 

 

VB.NET to Verify S/MIME Signature

Download VB.NET Project Files and Source Code

This VB.NET S/MIME example program shows how to verify (validate) a digitally signed MIME message. The MIME message can be a signed-data message (x-pkcs7-mime) or one with a detached signature (x-pkcs7-signature). The process of verifying the signature unwraps the MIME message back to its original unsigned state, where the message contents can be easily accessed.

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents VerifySig As System.Windows.Forms.Button
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.VerifySig = New System.Windows.Forms.Button()
        Me.ListBox1 = New System.Windows.Forms.ListBox()
        Me.SuspendLayout()
        '
        'VerifySig
        '
        Me.VerifySig.Location = New System.Drawing.Point(24, 24)
        Me.VerifySig.Name = "VerifySig"
        Me.VerifySig.Size = New System.Drawing.Size(96, 32)
        Me.VerifySig.TabIndex = 0
        Me.VerifySig.Text = "Verify Signature"
        '
        'ListBox1
        '
        Me.ListBox1.Location = New System.Drawing.Point(24, 72)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(344, 212)
        Me.ListBox1.TabIndex = 1
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(384, 310)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1, Me.VerifySig})
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    ' Loads a signed message, unwraps the security envelopes, and determines
    ' if the signature is valid.  The signed MIME message can be an opaque
    ' signed-data message, or it can be one with a detached PKCS7 signature.
    Private Sub VerifySig_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VerifySig.Click

        Dim mime As New Chilkat.Mime()

        ' Get a 30-day trial code from http:'www.chilkatsoft.com/register30.asp
        mime.UnlockComponent("UnlockCode")
        mime.LoadMimeFile("signed.txt")

        ' Determine if this is a signed message or not.
        If (mime.IsSigned()) Then
            ListBox1.Items.Add("Message is signed")
        Else
            ListBox1.Items.Add("Message is not signed")
        End If

        ' Unwrap the security.  This is the signature validation.
        ' The results are stored within the Mime object and can be queried
        ' afterwards.
        Dim signatureValid As Boolean
        signatureValid = mime.UnwrapSecurity()
        If (signatureValid) Then
            ListBox1.Items.Add("Signed message has been validated")
        Else
            ListBox1.Items.Add("Signed message not validated")
        End If

        ' Get the first signing certificate.
        Dim cert As Chilkat.Cert
        cert = mime.GetSignerCert(0)
        ListBox1.Items.Add("Signed By: " + cert.SubjectDN)

        ' How many signatures are there?
        ListBox1.Items.Add("Num Signatures: " + Str(mime.NumSignerCerts))

        ' This example uses a MIME message that included a GIF attachment.
        ' Save the GIF to a file.
        Dim gifAttachment As Chilkat.Mime
        gifAttachment = mime.GetPart(1)
        gifAttachment.SaveBody("dude.gif")

        ' Save the unwrapped (and now unsigned) MIME messages
        ' in both XML and MIME formats.
        mime.SaveXml("unsigned.xml")
        mime.SaveMime("unsigned.txt")

    End Sub
End Class


Important: The download for this example does not contain the ChilkatDotNet.dll which
must be downloaded and installed separately at http://www.chilkatsoft.com/downloads.asp.
Once installed, add a reference to the DLL in the project by following the instructions at
http://www.example-code.com/vbdotnet/step2.asp

 

 

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

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

Mail Component · XML Parser