Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript



VB Examples

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

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


VB Strings
VB Byte Array

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

 

 

 

 

 

 

 

Verify S/MIME Signed Message

Download Visual Basic Project Files and Source Code

This Visual Basic sample program shows how to unwrap the security envelopes in an S/MIME message and verify all signatures present. It can handle both detached signatures (x-pkcs7-signature MIME content-type) or opaque signed-data messages (x-pkcs7-mime content type). The process of verifying the S/MIME signature restores the MIME to its original unsigned state, which makes it easy to access the contents of the message.

' 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 Command1_Click()

        Dim mime As New ChilkatMime

        ' 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() = 1) Then
            ListBox1.AddItem "Message is signed"
        Else
            ListBox1.AddItem "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 Long
        signatureValid = mime.UnwrapSecurity()
        If (signatureValid = 1) Then
            ListBox1.AddItem "Signed message has been validated"
        Else
            ListBox1.AddItem "Signed message not validated"
        End If

        ' Get the first signing certificate.
        Dim cert As ChilkatCert
        Set cert = mime.GetSignerCert(0)
        ListBox1.AddItem "Signed By: " + cert.SubjectDN

        ' How many signatures are there?
        ListBox1.AddItem "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 ChilkatMime
        Set 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

' Relevant keywords: mime type, mime format, mime tool, mime decoder, mime file, mime decode
' mime attachment, mime reader, mime download, mime converter, mime content type,
' mime encoding, mime version 1.0, mime pic, mime video, mime software, mime viewer,
' mime file, mime protocol, mime rfc, mime header, email mime, mail mime, mime decoding,
' mime message, mime file type, mime html, mime downloads, mime parser, mime pdf, convert mime
'
'   content-disposition: attachment; filename="smime.p7m"
'   content-transfer-encoding: base64
'   content-type: application/x-pkcs7-mime;
'       name="smime.p7m";
'       smime-type=signed-data





 

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

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