Home > Language Reference > Classes > StreamCipher

InitRC4 Method

Sets the encoding/decoding scheme to RC4.

Syntax

Public Sub InitRC4(ByRef sKey As String)

ParameterDescription
sKeyPrivate key.

Remarks

The InitRC4 method sets the encoding/decoding scheme to RC4®, and allocates the necessary internal buffers. If the object was already initialized, buffers allocated for the previous encoding scheme are freed, and any pending data are lost.

RC4® is a variable key-size encryption algorithm, based on the use of random permutations. Unlike other encryption schemes, it can be expected to run very quickly. Furthermore, many analysts have scrutinized the algorithm and it is considered as secure. Detailed information on RC4® can easily be found on the internet.

The algorith needs a private key to generate random permutations. This key must be specified in the sKey parameter at the time the object is initialized, and cannot be changed later. For security reasons, it is strongly advised not to store this private key in your executable, as in the following naive example:

Dim c As New StreamCipher
c.InitRC4 "A Private Key" ' This string can easily be found in your compiled executable

Instead, you should encrypt the key itself, and/or store it in a separate database. If the design of your application allows this, an even more secure approach would be not to store the key, but to derive it from available data. For example, you could generate a key by applying a secure hash function to the device serial number, or to any user input such as a password.

You can refer to the StreamCipher introductory page for an example of using this function to encrypt and backup a native database on a VFS card.

Note: depending on the cryptographic policies in your country, it may or may not be legal to use this algorithm in your own software, and/or to import or export software using this algorithm.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A