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

 

 

 

 

 

 

Find Certificates for Signing

This VB.NET example program shows how to iterate over the certificates on a computer to find those that can be used for signing.

        ' What certificates exist on my computer, and which
        ' ones can I use for creating digital signatures?
        Dim ccs As New Chilkat.CreateCS()

        Dim crypt As New Chilkat.Crypt2()

        Dim unlocked As Boolean
        unlocked = crypt.UnlockComponent("anything begins 30-day trial")
        If unlocked = 0 Then
            MsgBox("Encryption component is not unlocked!")
            Exit Sub
        End If

        ' Use the Microsoft Enhanced Cryptographic Service Provider
        ' Add a reference to ChilkatUtil for the ChilkatCSP object
        Dim csp As New Chilkat.Csp()
        csp.SetProviderMicrosoftEnhanced()
        crypt.SetCSP(csp)

        ' -------------------------------------------------------
        ' First check the current-user certificate store.
        ' If running in ASP.NET, do not check the current-user store.
        ' -------------------------------------------------------
        Dim certStore As Chilkat.CertStore
        certStore = ccs.OpenCurrentUserStore()

        TextBox1.Text = "Current User Certificate Store -------------"
        TextBox1.Text = TextBox1.Text & vbCrLf & "-"

        Dim cert As Chilkat.Cert
        Dim signature As String

        Dim i As Integer
        For i = 0 To certStore.NumCertificates - 1
            cert = certStore.GetCertificate(i)

            ' Display the certificate we are testing..
            TextBox1.Text = TextBox1.Text & vbCrLf & cert.SubjectDN

            ' Set the certificate to be used for signing, and our output string encoding.
            crypt.SetSigningCert(cert)
            crypt.EncodingMode = "base64"

            ' Try signing....
            signature = crypt.SignStringENC("This is a test")
            If Len(signature) = 0 Then
                ' Failed to create signature
                TextBox1.Text = TextBox1.Text & vbCrLf & "FAILED"
                If cert.HasPrivateKey() = 0 Then
                    TextBox1.Text = TextBox1.Text & vbCrLf & "NO PRIVATE KEY"
                End If
                TextBox1.Text = TextBox1.Text & vbCrLf & crypt.LastErrorText
            Else
                TextBox1.Text = TextBox1.Text & vbCrLf & "SUCCESS!"
                TextBox1.Text = TextBox1.Text & vbCrLf & crypt.LastErrorText
            End If

            TextBox1.Text = TextBox1.Text & vbCrLf & "----------------" & vbCrLf
            TextBox1.Refresh()
        Next


        ' -------------------------------------------------------
        ' Now check the local machine certificate store.
        ' -------------------------------------------------------
        certStore = ccs.OpenLocalSystemStore()

        TextBox1.Text = TextBox1.Text & vbCrLf & "---------------------------------------------"
        TextBox1.Text = TextBox1.Text & vbCrLf & "Local Machine Certificate Store -------------"
        TextBox1.Text = TextBox1.Text & vbCrLf & "---------------------------------------------"
        TextBox1.Text = TextBox1.Text & vbCrLf & "-"

        For i = 0 To certStore.NumCertificates - 1
            cert = certStore.GetCertificate(i)

            ' Display the certificate we are testing..
            TextBox1.Text = TextBox1.Text & vbCrLf & cert.SubjectDN

            ' Set the certificate to be used for signing, and our output string encoding.
            crypt.SetSigningCert(cert)
            crypt.EncodingMode = "base64"

            ' Try signing....
            signature = crypt.SignStringENC("This is a test")
            If Len(signature) = 0 Then
                ' Failed to create signature
                TextBox1.Text = TextBox1.Text & vbCrLf & "FAILED"
                If cert.HasPrivateKey() = 0 Then
                    TextBox1.Text = TextBox1.Text & vbCrLf & "NO PRIVATE KEY"
                End If
                TextBox1.Text = TextBox1.Text & vbCrLf & crypt.LastErrorText
            Else
                TextBox1.Text = TextBox1.Text & vbCrLf & "SUCCESS!"
                TextBox1.Text = TextBox1.Text & vbCrLf & crypt.LastErrorText
            End If

            TextBox1.Text = TextBox1.Text & vbCrLf & "----------------" & vbCrLf
            TextBox1.Refresh()
        Next


        ' -------------------------------------------------------
        ' Now check Outlook's certificate store.
        ' If running in ASP.NET, do not check the Outlook store.
        ' -------------------------------------------------------
        certStore = ccs.OpenOutlookStore()
        If certStore Is Nothing Then
            Exit Sub
        End If

        TextBox1.Text = TextBox1.Text & vbCrLf & "---------------------------------------------"
        TextBox1.Text = TextBox1.Text & vbCrLf & "Outlook Certificate Store -------------------"
        TextBox1.Text = TextBox1.Text & vbCrLf & "---------------------------------------------"
        TextBox1.Text = TextBox1.Text & vbCrLf & "-"

        For i = 0 To certStore.NumCertificates - 1
            cert = certStore.GetCertificate(i)

            ' Display the certificate we are testing..
            TextBox1.Text = TextBox1.Text & vbCrLf & cert.SubjectDN

            ' Set the certificate to be used for signing, and our output string encoding.
            crypt.SetSigningCert(cert)
            crypt.EncodingMode = "base64"

            ' Try signing....
            signature = crypt.SignStringENC("This is a test")
            If Len(signature) = 0 Then
                ' Failed to create signature
                TextBox1.Text = TextBox1.Text & vbCrLf & "FAILED"
                If cert.HasPrivateKey() = 0 Then
                    TextBox1.Text = TextBox1.Text & vbCrLf & "NO PRIVATE KEY"
                End If
                TextBox1.Text = TextBox1.Text & vbCrLf & crypt.LastErrorText
            Else
                TextBox1.Text = TextBox1.Text & vbCrLf & "SUCCESS!"
                TextBox1.Text = TextBox1.Text & vbCrLf & crypt.LastErrorText
            End If

            TextBox1.Text = TextBox1.Text & vbCrLf & "----------------" & vbCrLf
            TextBox1.Refresh()
        Next




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