Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
String
Tar
Unicode
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor


VB Strings
VB Byte Array

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

Public-Key Encrypt Text in a TextBox

Download Chilkat Crypt ActiveX

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.