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
3DES Public-Key Encryption using Digital CertificatesDownload: Chilkat .NET Assemblies VB.NET source code showing how to do 3DES public-key encryption and decryption. ' 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")
' Use public-key encryption.
crypt.CryptAlgorithm = "PKI"
' Use 3DES encryption.
Dim csp As New Chilkat.Csp()
csp.SetProviderMicrosoftEnhanced()
csp.SetEncryptAlgorithm("3DES")
crypt.SetCSP(csp)
' 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.SetEncryptCert(cert)
' Tell the crypt object to base-64 encode the encrypted data.
crypt.EncodingMode = "base64"
' File a byte array to encrypt
Dim inputData(10) As Byte
Dim i As Integer
For i = 1 To 10
inputData(i) = i
Next
' Encrypt the byte array.
' To encrypt, only the public-key is needed (when using PKI).
Dim eStr As String
eStr = crypt.EncryptBytesENC(inputData)
If (eStr.Length = 0) Then
MsgBox(crypt.LastErrorText)
Exit Sub
End If
MsgBox("Data encrypted: " & eStr)
' Now decrypt...
' To decrypt, the private key is needed. If this step fails but the encryption succeeded,
' it is probably because the public key is installed and accessible, but not the private key.
Dim decrypted() As Byte
decrypted = crypt.DecryptBytesENC(eStr)
MsgBox("Decrypted length = " & Str(decrypted.Length))
If (decrypted.Length = 0) Then
MsgBox(crypt.LastErrorText)
Else
For i = 0 To decrypted.Length - 1
If (decrypted(i) <> i) Then
MsgBox("Error in decrypted data!")
End If
Next
End If
Important: The download for this
example does not contain the ChilkatDotNet.dll which |
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.