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

 

 

 

 

 

 

Create and Verify a Digital Signature

This example demonstrates how to create and verify a digital signature. It signs an in-memory string, and then verifies it against the digital signature.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' Create a detached digital signature for an in-memory string
        ' using Chilkat Crypt2
        Dim crypt As New Chilkat.Crypt2()

        ' Any string passed to UnlockComponent begins the 30-day trial.
        Dim unlocked As Boolean
        unlocked = crypt.UnlockComponent("30-day trial")
        If Not unlocked Then
            MsgBox("Component is not unlocked")
            Exit Sub
        End If

        ' Return the digital signature in a base64-encoded string.
        crypt.EncodingMode = "base64"

        ' Select a digital certificate to use for signing.
        ' This certificate must have the private key already installed
        ' on the system (usually from a .pfx file).
        Dim cert As New Chilkat.Cert()
        Dim success As Boolean
        success = cert.LoadFromFile("myCert.cer")
        If Not success Then
            MsgBox(cert.LastErrorText)
            Exit Sub
        End If
        crypt.SetSigningCert(cert)

        ' Create the digital signature
        Dim stringToSign = "Hello World!"
        Dim signature As String
        signature = crypt.SignStringENC(stringToSign)
        If Len(signature) = 0 Then
            MsgBox(crypt.LastErrorText)
            Exit Sub
        End If

        TextBox1.Text = signature

        ' Verify the digital signature against the original text.
        ' Use a different crypt object for demonstration purposes.
        Dim c2 As New Chilkat.Crypt2()
        c2.EncodingMode = "base64"

        Dim valid As Boolean
        valid = c2.VerifyStringENC(stringToSign, signature)
        If Not valid Then
            MsgBox("The original data has been altered")
        Else
            MsgBox("The signature has been verified")
        End If

        Dim cert2 As Chilkat.Cert
        cert2 = c2.GetLastCert()

        MsgBox("Certifcate: " & cert2.SubjectDN)

        ' The certificate can now be checked for validity with respect
        ' to revocation, trusted root, certificate signature, and expiration.
        ' Refer to the Chilkat.Cert examples for this.

    End Sub



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