Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
String-to-String Public-Key Encryption / Decryption
Demonstrates how to use Chilkat Crypt for string-to-string public-key encryption and decryption.
Private Sub Command1_Click()
' String to string public-key encryption / decryption using digital certificates.
Dim crypt As New ChilkatCrypt2
crypt.UnlockComponent UnlockCode.Text
' Locate a certificate using Chilkat Cert
Dim StoreCreator As New ChilkatCreateCS
Dim certStore As ChilkatCertStore
Set certStore = StoreCreator.OpenCurrentUserStore()
If (certStore Is Nothing) Then
MsgBox StoreCreator.LastErrorText
Exit Sub
End If
Dim cert As ChilkatCert
Set cert = certStore.FindCertBySubject(CertSubject.Text)
If (cert Is Nothing) Then
MsgBox certStore.LastErrorText
Exit Sub
End If
' Encrypt and decrypt...
crypt.EncodingMode = "Base64"
crypt.CryptAlgorithm = "PKI"
crypt.SetEncryptCert cert
Text2.Text = crypt.EncryptStringENC(Text1.Text)
If (Len(Text2.Text) = 0) Then
MsgBox crypt.LastErrorText
Exit Sub
End If
Text3.Text = crypt.DecryptStringENC(Text2.Text)
If (Len(Text3.Text) = 0) Then
MsgBox crypt.LastErrorText
Exit Sub
End If
End Sub
Private Sub Form_Load()
' Create our certificate store factory object.
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()
' Get the number of certificates in the store.
NumCerts = certStore.NumCertificates
Dim cert As ChilkatCert
' Loop over the certificates, get each certificate and print information about each.
For Index = 0 To NumCerts - 1
Set cert = certStore.GetCertificate(Index)
List1.AddItem cert.SubjectCN + ", " + cert.SubjectE
Next
Set certStore = Nothing
Set certStore = StoreCreator.OpenLocalSystemStore()
' Get the number of certificates in the store.
NumCerts = certStore.NumCertificates
' Loop over the certificates, get each certificate and print information about each.
For Index = 0 To NumCerts - 1
Set cert = certStore.GetCertificate(Index)
List2.AddItem cert.SubjectCN + ", " + cert.SubjectE
Next
Set certStore = Nothing
Set certStore = StoreCreator.OpenOutlookStore()
' Get the number of certificates in the store.
NumCerts = certStore.NumCertificates
' Loop over the certificates, get each certificate and print information about each.
For Index = 0 To NumCerts - 1
Set cert = certStore.GetCertificate(Index)
List3.AddItem cert.SubjectCN + ", " + cert.SubjectE
Next
Set certStore = Nothing
End Sub
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.