ENCRYPT Function

Encrypts a string.

Syntax

ENCRYPT(string, key, method)

Syntax Elements

string An expression that evaluates to the string to be encrypted. string can be a plain or an encrypted text string.

key An expression that evaluates to a string containing the encryption key. When using method 1 (see method), this can be a null string ("").

method An integer expression specifying one of the following encryption methods:

0 A general purpose network encryption/decryption scheme. It can be used for encoding or decoding sensitive data which is to be transferred outside of the machine. It uses only the last character of key.

1 A simple rotation algorithm that affects only the alphabetic characters A-Z and a-z. These letters are rotated right 13 places. This is an algorithm sometimes called ROT13. It is easily breakable, but it is good for scrambling textual material for online data. Method 1 does not use key, but it must be present even as a null string ("").

2 XOR.MOD11 algorithm that uses only the last character of key. This algorithm uses the key as a seed, which has its five low-order bits XOR'd with each character in string. After each XOR, the seed is incremented by one.

3 A one-to-one exclusive OR between the string in string and an infinite garbage string generated through a Fibonacci algorithm. This method uses the entire key in key.

4 Encrypts using a key from the REK file. key must be the item-id of a key item.

5 Uses either Data Encryption Standard (DES) encryption with the Cipher Block Chaining (CBC) algorithm or Triple DES. key must be a dynamic array where the first attribute is 1 for DES:CBC or 2 for Triple DES, and the second attribute is the encryption key (8-character for DES:CBC, or 16-character for Triple DES).

Return Value

The encrypted string.

If method 4 is specified, and the user does not have permission to use the specified key item or if the specified key item does not exist, string is returned unchanged.

Examples

TEST = ENCRYPT("EXAMPLE", "BC", 0)

Sets TEST to the string "QMOVHWO."

TEST = ENCRYPT("EXAMPLE", "", 1)

Sets TEST to the string "RKNZCYR."

TEST = ENCRYPT("EXAMPLE", "2", 2)

Sets TEST to the string "C_IDZGI."

E = ENCRYPT(S, "1":@AM:"MYENCKEY", 5)
FOR I = 1 TO LEN(E)
    PRINT DTX(SEQ(E[I,1])):" ":
NEXT I
PRINT

Displays 0 0 0 10 0 0 0 7 8 23 8 87 31 EF 54 62.

See Also

DECRYPT function.

Go to top button