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
Service
PPMD
Deflate
DH Key Exchange
DSA


VB Strings
VB Byte Array

Unreleased...
Bzip2
LZW
Bz2
Icon

 

 

 

 

 

 

 

Create and Verify Digital Signature

Uses Chilkat Crypt2 to create and verify a detached digital signature.

    Dim crypt As New ChilkatCrypt2
    crypt.UnlockComponent "test"

    ' Select a digital certificate for signing.
    Dim StoreCreator As ChilkatCreateCS
    Set StoreCreator = New ChilkatCreateCS
    
    ' Create a certificate store object representing the registry-based
    ' current user certificate store.
    Dim certStore As ChilkatCertStore
    Set certStore = StoreCreator.OpenCurrentUserStore()
    
    ' Find a certificate matching an email address.
    Dim cert As ChilkatCert
    Set cert = certStore.FindCertBySubjectE("admin@tagtooga.com")
    If (cert Is Nothing) Then
        MsgBox "Certificate not found!"
        Exit Sub
    End If
        
    ' Use this certificate.
    crypt.SetSigningCert cert
    
    Dim fileData As Variant
    Dim sigData As Variant
    
    fileData = crypt.ReadFile("sample.pdf")
    If IsNull(fileData) Then
        MsgBox crypt.LastErrorText
        Exit Sub
    End If
    
    sigData = crypt.SignBytes(fileData)
    If IsNull(sigData) Then
        MsgBox crypt.LastErrorText
        Exit Sub
    End If
    
    success = crypt.WriteFile("signature.dat", sigData)
    If (success = 0) Then
        MsgBox crypt.LastErrorText
    End If
    
    MsgBox "OK!"
    
    ' Now verify it...
    Dim sigData2 As Variant
    
    sigData2 = crypt.ReadFile("signature.dat")
    If IsNull(sigData2) Then
        MsgBox crypt.LastErrorText
        Exit Sub
    End If
    
    sigOK = crypt.VerifyBytes(fileData, sigData2)
    If (sigOK = 1) Then
        MsgBox "Signature is valid, the file is unchanged."
    Else
        MsgBox "Invalid signature, the file may have been altered."
    End If

 

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

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