VB.NET Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CUnicode C++Unicode CMFCDelphi DLLDelphi ActiveXFoxProJavaPerlPHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

VB.NET Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
PFX
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar Archive
Upload
XML
XMP
Zip Compression
Misc

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

Byte Array
VB.NET FTPS
System.IO

 

 

 

 

 

 

Find Certificates for Signing

Download: Chilkat .NET Assemblies

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

 

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