*BinaryFile*

Back to the start
Back to the libraries overview


Overview (Crypto)
Decrypt (Crypto)
Encrypt (Crypto)
New1 (Crypto)

Overview (Crypto) Top

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


Decrypt (Crypto) Top

Decrypts an array of bytes and returns the decrypted data as an array.
The PassPhrase string must be the same as the PassPhrase used when encrypting the data.
Syntax: Decrypt (PassPhrase As String, Data As Byte() ) As Byte()


Encrypt (Crypto) Top

Encrypts an array of bytes and returns the encrypted data as an array of bytes.
Syntax: Encrypt (PassPhrase As String, Data As Byte() ) As Byte()


New1 (Crypto) Top

Initializes a Crypto object.
Syntax: New