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 for a File

This VB.NET sample code loads a file and creates a digitial signature. It then verifies the digital signature.

        ' This example uses the Chilkat .NET encryption library, which can be downloaded
        ' at http://www.chilkatsoft.com/downloads.asp

        ' Create an instance of the Chilkat encryption class.
        Dim success As Boolean
        Dim crypt As New Chilkat.Crypt2()

        ' Any code begins the 30-day trial.
        crypt.UnlockComponent("30-day-trial")

        ' Load the file to be signed into a byte array
        Dim oFile As System.IO.FileInfo
        oFile = New System.IO.FileInfo("fileToSign.dat")
        Dim oFileStream As System.IO.FileStream = oFile.OpenRead()
        Dim lBytes As Long = oFileStream.Length
        Dim fileData(lBytes) As Byte
        oFileStream.Read(fileData, 0, lBytes)
        oFileStream.Close()

        ' Load a certificate from a .cer file
        ' There are many other ways of loading a certificate...
        Dim cert As New Chilkat.Cert()
        success = cert.LoadFromFile("myCert.cer")
        If (Not success) Then
            MsgBox(cert.LastErrorText)
            Exit Sub
        End If

        ' Tell the crypt object to use the certificate.
        crypt.SetSigningCert(cert)

        ' Create a digital signature based on the file content.
        Dim signatureBytes() As Byte
        signatureBytes = crypt.SignBytes(fileData)
        If (signatureBytes.Length = 0) Then
            MsgBox(crypt.LastErrorText)
            Exit Sub
        End If

        ' Save the detached signature to a file.
        oFileStream = New System.IO.FileStream("signature.dat", System.IO.FileMode.Create)
        oFileStream.Write(signatureBytes, 0, signatureBytes.Length - 1)
        oFileStream.Close()

        MsgBox("Digital signature created!")

        ' Now verify the signature.
        Dim verified As Boolean
        verified = crypt.VerifyBytes(fileData, signatureBytes)
        If Not verified Then
            MsgBox(crypt.LastErrorText)
        Else
            MsgBox("Signature verified!")
        End If




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