ENCRYPT()

Top  Previous  Next

 

The ENCRYPT() function encrypts data for secure storage or transmission.

 

 

Format

 

ENCRYPT(data, key)

 

where

 

datais the string to be encrypted.

 

keyis the encryption key to be used.

 

 

The ENCRYPT() function applies the AES 128 bit encryption algorithm to the supplied data and returns the encrypted text. The key string may be up to 64 characters in length and may contain any character. It is automatically transformed into a form that is useable by the AES algorithm. For optimum data security, the key should be about 16 characters.

 

The encrypted data is post-processed so that it can never contain characters from the C0 control group (characters 0 to 31) or the mark characters. As a result of this operation, the encrypted data is slightly longer than the original source data.

 

 

Example

 

FUNCTION LOGIN()

  OPEN 'USERS' TO USR.F ELSE

     DISPLAY 'Cannot open USERS file'

     RETURN @FALSE

  END

  DISPLAY 'User name: ' :

  INPUT USERNAME, 20_:

  READ USER.REC FROM USR.F THEN

     FOR I = 1 TO 3

        DISPLAY 'Password: ' :

        INPUT PW,20_: HIDDEN

        IF ENCRYPT(PW, 'MySecretKey') = USR.REC<1> THEN RETURN @TRUE

        DISPLAY 'Password incorrect'

     NEXT I

  END

  RETURN @FALSE

END

 

The above function prompts for a user name and password, validating these against a record in the USERS file. The password field of this file is encrypted.

 

 

See also:

Data encryption, DECRYPT()