Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

November 1, 2005

VB6 to Encrypt a Credit Card Number

Here is a quick example using VB6 to encrypt/decrypt a credit card number:

Dim crypt2 As New ChilkatCrypt2
crypt2.UnlockComponent "30-day trial"

crypt2.CryptAlgorithm = "aes"
crypt2.EncodingMode = "base64″
‘ The VB6 string is Unicode, so make sure we are encrypting 1 byte/char…
crypt2.Charset = "ansi"

‘ Set a binary secret key. Make sure to set the KeyLength prior to this.
‘ We use the GenerateSecretKey method to convert an arbitrary password string
‘ to a binary secret key with the appropriate number of bits (128)
crypt2.KeyLength = 128
crypt2.SecretKey = crypt2.GenerateSecretKey("myPassword")

Dim ccNum As String
ccNum = "3121129011220090″ ‘ 16-digit credit card number (not a real one of course…)

‘ Encrypt and return as base64 string
‘ The encrypted string is about 42 characters
‘ 16 characters of encrypted data + 16 characters of padding
‘ which are base64 encoded, which expands data by approx 4/3rds.
Text1.Text = crypt2.EncryptStringENC(ccNum)

‘ Decrypt from base64 string.
Text2.Text = crypt2.DecryptStringENC(Text1.Text)

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.