Overview
Using the Crypto library you can encrypt and decrypt data with a specified key.
The Crypto library uses the Crypto API methods.
You must supply the same PassPhrase string when you encrypt and decrypt the data.
A 128 bit hash object is created from the PassPhrase (using the MD5 algorithm), and
from that object a 40 bit crypto key is generated.
The PassPhrase string should not be saved inside the code (as string).
Example: (you can download this example from Basic4ppc site)
'Crypto is a Crypto object and Bit is a Bitwise object
Sub Globals
Dim string(0) as Byte, secret(0) as Byte
PassPhrase = "my key" 'This is not recommended in real
applications!!!
End Sub
Sub App_Start
Form1.Show
Bit.New1
Crypto.New1
End Sub
Sub btnEncrypt_Click
string() =
Bit.StringToBytes(txtString.Text,0,StrLength(txtString.Text)) 'Convert
the string to an array of bytes.
secret() = Crypto.Encrypt(PassPhrase, string()) 'Save the
encrypted data.
for i = 0 to ArrayLen(secret())-1 'Show the encrypted data in the
TextBox
s = s & bit.DecToHex(secret(i))
next
txtString.Text = s
End Sub
Sub btnDecrypt_Click
string() = Crypto.Decrypt(PassPhrase,secret()) 'Decrypt the data.
txtString.Text = Bit.BytesToString(string(),0,ArrayLen(string())) 'Convert the array to a string.
End Sub