Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Public-Key Encrypt Text in a TextBox
RSA encryption and decryption of text in Visual Basic. Also does Base64 encoding/decoding and BZip2 compression/decompression.
Private Sub Encrypt_Click()
Dim crypt As New ChilkatCrypt2
' Load a digital certificate.
' You only need the public key to encrypt.
' The private key will be needed to decrypt,
' so your own certificate needs to be used.
Dim cert As New ChilkatCert
cert.LoadFromFile "matt.cer"
' Anything starts the 30-day trial
crypt.UnlockComponent "30DayTrial"
crypt.SetEncryptCert cert
' Setup the encryption parameters
' Compress the data before encrypting.
crypt.CompressionAlgorithm = "BZIP2"
' Use public-key encryption (as opposed to password-based symmetric encryption)
crypt.CryptAlgorithm = "PKI"
' Return the encrypted data as a Base64-encoded string.
crypt.EncodingMode = "BASE64"
' VB uses Unicode, so convert to ANSI (1 byte per char) before encrypting.
crypt.Charset = "ANSI"
Text2.Text = crypt.EncryptStringENC(Text1.Text)
Text1.Text = "OK, now press Decrypt"
End Sub
Private Sub Decrypt_Click()
Dim crypt As New ChilkatCrypt2
' Anything starts the 30-day trial
crypt.UnlockComponent "30DayTrial"
' Setup the encryption parameters
' After decrypting, decompress the data.
crypt.CompressionAlgorithm = "BZIP2"
' Use public-key encryption (as opposed to password-based symmetric encryption)
crypt.CryptAlgorithm = "PKI"
' Indicate that the data to be decrypted is base-64 encoded.
crypt.EncodingMode = "BASE64"
' VB uses Unicode, so convert from ANSI to Unicode after decrypting.
crypt.Charset = "ANSI"
Text1.Text = crypt.DecryptStringENC(Text2.Text)
If (Len(Text1.Text) = 0) Then
MsgBox crypt.LastErrorText
End If
Text3.Text = "There you go!"
End Sub
Private Sub Form_Load()
' Load the text box with some data.
Text1.Text = ""
For i = 1 To 300
Text1.Text = Text1.Text & Str(i) & " abcd 1234 zzzzzzzzzzzzz aaaaaaaaaaaa" & vbCrLf
Next
End Sub
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.