Navigation:  Reference > Functions >

ENCRYPTSTR()

Print this Topic Previous pageReturn to chapter overviewNext page

ENCRYPTSTR(1,2,3)

 

PURPOSE

 

This function will encrypt a string using the programmers choice of TwoFish, BlowFish, DES or RC2.

 

PARTS

 

1. f/c/e Requited -  Encryption type seTwoFish  / seBlowFish / seDES /seRC2

 

2. f/c/e Required - The string of characters to be encrypted

 

3. f/c/e Required - The encryption phrase or "key"

 

 

RETURN TYPE - A        

 

COMMENTS

Allows you to encrypt a string (for example, a password or some other sensitive data).  The encrypted string (always alphanumeric and it is case sensitive) can then be saved to a data file or a text (e.g. INI) file or anywhere that may be desired.  

 

The string may later be unencrypted using DECRYPTSTR().   If an invalid phrase is used when trying to decrypt, the string returned will be gibberish.

 

With this function you can choose four deferent types of encryption types TwoFish BlowFish DES or RC2.

 

Twofish is a 128-bit block cipher that accepts a variable-length key up to 256 bits.

 

Blowfish is a symmetric block cipher that can be used as a drop-in replacement for DES or IDEA. It takes a variable-length key, from 32 bits to 448 bits, making it ideal for both domestic and exportable use. Blowfish was designed in 1993 by Bruce Schneier as a fast, free alternative to existing encryption algorithms. Since then it has been analyzed considerably, and it is slowly gaining acceptance as a strong encryption algorithm. Blowfish is unpatented and license-free, and is available free for all uses.

 

DES encrypts and decrypts data in 64-bit blocks, using a 64-bit key (although the effective key strength is only 56 bits, as explained below). It takes a 64-bit block of plaintext as input and outputs a 64-bit block of ciphertext. Since it always operates on blocks of equal size and it uses both permutations and substitutions in the algorithm, DES is both a block cipher and a product cipher.

 

RC2 is a 64-bit block cipher with a variable size key. Its 18 rounds are arranged as a source-heavy Feistel network, with 16 rounds of one type (MIXING) punctuated by two rounds of another type (MASHING). A MIXING round consists of four applications of the MIX transformation, as shown in the diagram. RC2 is vulnerable to a related-key attack using 234 chosen plaintexts (Kelsey et al, 1997).

 

NOTE: The encrypted string returned by this function will be larger than the original/input string If you are going to save this information into a  data field you need to make sure the fields size will large enough to store  the encrypted data.

 

NOTE: Including the encryption Key/phrase "as is" directly in your code (rather than say reading it from a field or from some external source) is not secure when used in a legacy ".RUN" program.   In a newer style RWN programs, this is because ".RWN" compiled programs are always encrypted.

 

EXAMPLE

 

Define string1,string2,string3 type a size 100

Define PassPhrase,filename type a size 80

define twofish,blowfish,des,rc2,md5,sha1 type l

 

ONStart:

String1 = 'Now is the time for all good men to come to the aid of there country'

PassPhrase = 'Computer Accounting Solutions'

Twofish = true

ret

 

//   Events for: btnencode Object Type: TGlyphBtn

 btnencode.Click:

  if twofish

     string2 = encryptstr(setwofish,String1,passPhrase)

  else_if blowfish

     string2 = encryptstr(seBlowfish,String1,passPhrase)

  else_if des

     string2 = encryptstr(sedes,String1,passPhrase)

  else_if rc2

     string2 = encryptstr(serc2,String1,passPhrase)

  else

    msg 'Error encoding not set'

  endif

  Ret

 

See Also

Decryptstr()

 

 


Page url: http://www.cassoftware.com/tas/manual/encryptstr.htm