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).
6 Uses the standard Base64 encoding algorithm to encode the supplied string. Method 6 does not use key, but it must be present even as a null string ("").
7 Provides access to the openSSL message digest algorithms for MD4, MD5, MDC2, RIPEMD160, whirlpool, SHA0, SHA1, SHA224, SHA256, SHA384 & SHA512. The algorithm to use is passed as the key parameter of the function. The returned data is binary so care must be taken to process values such as character 255 that may occur in the result.
8 Provides access to the openSSL ciphers for AES-128-CBC, AES-192-CBC, AES-256-CBC, DES-CBC and DES-EDE3-CBC. The cipher, key (in hex) and initialisation vector (in hex) are passed as an attribute separated list in the key parameter. The returned data is binary so care must be taken to process values such as character 255 that may occur in the result.
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.
Example 1
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
.
Example 2
DIGEST = ENCRYPT("HELLO WORLD", "SHA512", 7) HEX = "" FOR A = 1 TO LEN(DIGEST) HEX:=DTX(SEQ(DIGEST[A,1]))"R%2" NEXT A PRINT DOWNCASE(HEX)
Displays 13d6c73ac8cceeff9ff6b0ba2ce19c5fc47ac21f9fd403c151fe88e0fd39f4223c29bc9bded59e1e3f272fd969fd6e2e6e35be35072e742c4b36fec48feb87df
.
Sets DIGEST to the SHA512 digest of the string "HELLO WORLD" and then displays the result in hexadecimal (variable HEX). This example takes into account that the resulting digest contains the character 255 (FF).
Example 3
IV = OCONV("16 characters!?#","MCAX") KEY = OCONV("Thirty Two character secret key!","MCAX") CIPHER = "AES-256-CBC" DIGEST = ENCRYPT("HELLO WORLD",CIPHER:@AM:KEY:@AM:IV,8) HEX = "" FOR A = 1 TO LEN(DIGEST) HEX:=DTX(SEQ(DIGEST[A,1]))"R%2" NEXT A PRINT DOWNCASE(HEX)
Displays de1ab4f1df9fa6831c3cf59abea09200
.
Sets DIGEST to the result of applying the AES-256-AES cipher to encrypt the string "HELLO WORLD" using a secret key (KEY) and an initialisation vector (IV) and then displays the result in hexadecimal (variable HEX). This example takes into account that the resulting digest may contain the character 255 (FF).
See Also
DECRYPT function.