Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Verify S/MIME Signed MessageThis 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
mime.UnlockComponent "Anything for 30-day trial"
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
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.