3.8. Cryptographic Functions

Qore's cryptography support is provided by the OpenSSL library. Most of the encryption and decryption functions in this section accept an optional initialization vector, which is data used as initial input for the first block in chained encryption algorithms. Subsequent blocks take input from the last block encrypted/decrypted. If a function accepts an initialization vector and one is not supplied, then a default value of 8 zero bytes will be used.

Some functions require fixed-length keys, and some allow the use of variable-length keys. For functions requiring fixed-length keys any excess bytes are ignored. The same applies to initialization vector arguments.

The following is an example of a function that uses /dev/random to read in a random key for use with encryption functions:

# read a key from /dev/random and return the key
sub get_key($size)
{
    # throw an exception if an invalid key size was passed
    if (!$size || $size < 0)
        throw "GET-KEY-ERROR", sprintf("invalid size = %n", $size);
    my $f = new File();
    # File::open2() will throw an exception if /dev/random cannot be opened for reading
    $f.open2("/dev/random");
    return $f.readBinary($size);
}

3.8.1. blowfish_encrypt_cbc()

Synopsis

Encrypts data using the Cipher Block Chaining function for the blowfish algorithm using a variable-length key and an optional initialization vector. Returns a binary object of the encrypted data.

Usage
blowfish_encrypt_cbc(input_data, key, [init_vector])
Example
$bin = blowfish_encrypt_cbc("hello there", $key);

Table 3.150. Arguments and Return Values for blowfish_encrypt_cbc()

Argument Type

Return Type

Description

String | Binary, String Binary, [String | Binary]

Binary

Encrypts data using the Cipher Block Chaining function for the blowfish algorithm; accepts a variable-length key (recommended 16-bytes or more). The initialization vector must be at least 8 bytes long if present.


Table 3.151. Exceptions thrown by blowfish_encrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

BLOWFISH-ENCRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.2. blowfish_decrypt_cbc()

Synopsis

Decrypts data using the Cipher Block Chaining function for the blowfish algorithm using a variable-length key. This function returns a binary object, for an equivalent function that decrypts to a string, see blowfish_decrypt_cbc_to_string().

Usage
blowfish_decrypt_cbc(binary, key, [init_vector])
Example
$bin = blowfish_decrypt_cbc("hello there", $key);

Table 3.152. Arguments and Return Values for blowfish_decrypt_cbc()

Argument Type

Return Type

Description

Binary, String | Binary, [String | Binary]

Binary

Decrypts data using the Cipher Block Chaining function for the blowfish algorithm using a variable-length key.


Table 3.153. Exceptions thrown by blowfish_decrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

BLOWFISH-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.3. blowfish_decrypt_cbc_to_string()

Synopsis

Decrypts data to a string using the Cipher Block Chaining function for the blowfish algorithm using a variable-length key. This function returns a string, for an equivalent function that decrypts to a binary object, see blowfish_decrypt_cbc().

Usage
blowfish_decrypt_cbc_to_string(binary, key, [init_vector])
Example
$str = blowfish_decrypt_cbc_to_string($bin, $key);

Table 3.154. Arguments and Return Values for blowfish_decrypt_cbc_to_string()

Argument Type

Return Type

Description

Binary, Key, [init_vector]

String

Decrypts data to a string using the Cipher Block Chaining function for the blowfish algorithm using a variable-length key.


Table 3.155. Exceptions thrown by blowfish_decrypt_cbc_to_string()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

BLOWFISH-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.4. des_encrypt_cbc()

Synopsis

Encrypts data using the Cipher Block Chaining function for the DES algorithm using an 8-byte key. Returns a binary object of the encrypted data.

Usage
des_encrypt_cbc(input_data, key, [init_vector])
Example
$bin = des_encrypt_cbc($text, $key);

Table 3.156. Arguments and Return Values for des_encrypt_cbc()

Argument Type

Return Type

Description

String | Binary, String | Binary, [String | Binary]

Binary

Encrypts data using the Cipher Block Chaining function for the DES algorithm. The key must be at least 8-bytes long (only the first 8 bytes will be used). If the init_vector is present it must also be at least 8 bytes long.


Table 3.157. Exceptions thrown by des_encrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

DES-ENCRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.5. des_decrypt_cbc()

Synopsis

Decrypts data using the Cipher Block Chaining function for the DES algorithm using an 8 byte key. This function returns a binary object, for an equivalent function that decrypts to a string, see des_decrypt_cbc_to_string().

Usage
des_decrypt_cbc(binary, key, [init_vector])

Table 3.158. Arguments and Return Values for des_decrypt_cbc()

Argument Type

Return Type

Description

Binary, String | Binary, [String | Binary]

Binary

Decrypts data using the Cipher Block Chaining function for the DES algorithm using an 8-byte key. If the init_vector is present it must also be at least 8 bytes long.


Table 3.159. Exceptions thrown by des_decrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

DES-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.6. des_decrypt_cbc_to_string()

Synopsis

Decrypts data using the Cipher Block Chaining function for the DES algorithm using an 8-byte key. This function returns a string, for an equivalent function that decrypts to a binary object, see des_decrypt_cbc().

Usage
des_decrypt_cbc_to_string(binary, key, [init_vector])

Table 3.160. Arguments and Return Values for des_decrypt_cbc_to_string()

Argument Type

Return Type

Description

Binary, Key, [init_vector]

String

Decrypts data using the Cipher Block Chaining function for the DES algorithm using an 8-byte key. If the init_vector is present it must also be at least 8 bytes long.


Table 3.161. Exceptions thrown by des_decrypt_cbc_to_string()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

DES-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.7. des_ede_encrypt_cbc()

Synopsis

Encrypts data using the Cipher Block Chaining function for the two-key triple DES algorithm using two eight-byte keys (set by a single 16-byte key argument). Returns a binary object of the encrypted data.

Usage
des_ede_encrypt_cbc(input_data, key, [init_vector])
Example
$bin = des_ede_encrypt_cbc($text, $key);

Table 3.162. Arguments and Return Values for des_ede_encrypt_cbc()

Argument Type

Return Type

Description

String | Binary

Binary

Encrypts data using the Cipher Block Chaining function for the two-key triple DES algorithm. The key argument must be at least 16 bytes long; only the first 16 bytes of the key argument will be used for the two 8-byte keys. If the init_vector argument is present, it must be at least 8 bytes long.


Table 3.163. Exceptions thrown by des_ede_encrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

DES-ENCRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.8. des_ede_decrypt_cbc()

Synopsis

Decrypts data using the Cipher Block Chaining function for the two-key triple DES algorithm using two eight-byte keys (set by a single 16-byte key argument). This function returns a binary object, for an equivalent function that decrypts to a string, see des_ede_decrypt_cbc_to_string().

Usage
des_ede_decrypt_cbc(binary, key, [init_vector])
Example
$bin = des_ede_decrypt_cbc($data, $key);

Table 3.164. Arguments and Return Values for des_ede_decrypt_cbc()

Argument Type

Return Type

Description

Binary, String | Binary, [String | Binary]

Binary

Decrypts data using the Cipher Block Chaining function for the two-key triple DES algorithm. The key argument must be at least 16 bytes long; only the first 16 bytes of the key argument will be used for the two 8-byte keys. If the init_vector argument is present, it must be at least 8 bytes long.


Table 3.165. Exceptions thrown by des_ede_decrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

DES-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.9. des_ede_decrypt_cbc_to_string()

Synopsis

Decrypts data to a string using the Cipher Block Chaining function for the two-key triple DES algorithm using two eight-byte keys (set by a single 16-byte key argument). This function returns a string, for an equivalent function that decrypts to a binary object, see des_ede_decrypt_cbc().

Usage
des_ede_decrypt_cbc_to_string(binary, key, [init_vector])
Example
$str = des_ede_decrypt_cbc_to_string($data, $key);

Table 3.166. Arguments and Return Values for des_ede_decrypt_cbc_to_string()

Argument Type

Return Type

Description

Binary, String | Binary, [String | Binary]

String

Decrypts data to a string using the Cipher Block Chaining function for the two-key triple DES algorithm. The key argument must be at least 16 bytes long; only the first 16 bytes of the key argument will be used for the two 8-byte keys. If the init_vector argument is present, it must be at least 8 bytes long.


Table 3.167. Exceptions thrown by des_ede_decrypt_cbc_to_string()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

DES-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.10. des_ede3_encrypt_cbc()

Synopsis

Encrypts data using the Cipher Block Chaining function for the three-key triple DES algorithm using three 8-byte keys (set by a single 24-byte key argument) and an optional 8-byte initialization vector. Returns a binary object of the encrypted data.

Usage
des_ede3_encrypt_cbc(data, key, [init_vector])
Example
$bin = des_ede3_encrypt_cbc($data, $key);

Table 3.168. Arguments and Return Values for des_ede3_encrypt_cbc()

Argument Type

Return Type

Description

String | Binary, String | Binary, [String | Binary]

Binary

Encrypts data using the Cipher Block Chaining function for the three-key triple DES algorithm using three 8-byte keys (set by a single 24-byte key argument) and an optional 8-byte initialization vector. Returns a binary object of the encrypted data.


Table 3.169. Exceptions thrown by des_ede3_encrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

DES-ENCRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.11. des_ede3_decrypt_cbc()

Synopsis

Decrypts data using the Cipher Block Chaining function for the three-key triple DES algorithm using three 8-byte keys (set by a single 24-byte key argument) and an optional 8-byte initialization vector. This function returns a binary object, for an equivalent function that decrypts to a string, see des_ede3_decrypt_cbc_to_string().

Usage
des_ede3_decrypt_cbc(encrypted_data, key, [init_vector])
Example
$bin = des_ede3_decrypt_cbc($data, $key);

Table 3.170. Arguments and Return Values for des_ede3_decrypt_cbc()

Argument Type

Return Type

Description

Binary, Key, [init_vector]

Binary

Decrypts data using the Cipher Block Chaining function for the three-key triple DES algorithm.


Table 3.171. Exceptions thrown by des_ede3_decrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

DES-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.12. des_ede3_decrypt_cbc_to_string()

Synopsis

Decrypts data to a string using the Cipher Block Chaining function for the three-key triple DES algorithm using three 8-byte keys (set by a single 24-byte key argument) and an optional 8-byte initialization vector. This function returns a string, for an equivalent function that decrypts to a binary object, see des_ede3_decrypt_cbc().

Usage
des_ede3_decrypt_cbc_to_string(encrypted_data, key, [init_vector])
Example
$str = des_ede3_decrypt_cbc_to_string($data, $key);

Table 3.172. Arguments and Return Values for des_ede3_decrypt_cbc_to_string()

Argument Type

Return Type

Description

Binary, String | Binary, [String | Binary]

String

Decrypts data to a string using the Cipher Block Chaining function for the three-key triple DES algorithm using three 8-byte keys (set by a single 24-byte key argument) and an optional 8-byte initialization vector.


Table 3.173. Exceptions thrown by des_ede3_decrypt_cbc_to_string()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

DES-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.13. desx_encrypt_cbc()

Synopsis

Encrypts data using the Cipher Block Chaining function for RSA's DESX algorithm using a 24-byte key and an optional 8-byte initialization vector. Returns a binary object of the encrypted data.

Usage
desx_encrypt_cbc(data, key, [init_vector])
Example
$bin = desx_encrypt_cbc($data, $key);

Table 3.174. Arguments and Return Values for desx_encrypt_cbc()

Argument Type

Return Type

Description

String | Binary, String | Binary, [String | Binary]

Binary

Encrypts data using the Cipher Block Chaining function for RSA's DESX algorithm using a 24-byte key and an optional 8-byte initialization vector.


Table 3.175. Exceptions thrown by desx_encrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

DESX-ENCRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.14. desx_decrypt_cbc()

Synopsis

Decrypts data using the Cipher Block Chaining function for RSA's DESX algorithm using a 24-byte key and an optional 8-byte initialization vector. This function returns a binary object, for an equivalent function that decrypts to a string, see desx_decrypt_cbc_to_string().

Usage
desx_decrypt_cbc(encrypted_data, key, [init_vector])
Example
$bin = desx_decrypt_cbc($data, $key);

Table 3.176. Arguments and Return Values for desx_decrypt_cbc()

Argument Type

Return Type

Description

Binary, Key, [init_vector]

Binary

Decrypts data using the Cipher Block Chaining function for RSA's DESX algorithm using a 24-byte key and an optional 8-byte initialization vector.


Table 3.177. Exceptions thrown by desx_decrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

DESX-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.15. desx_decrypt_cbc_to_string()

Synopsis

Decrypts data to a string using the Cipher Block Chaining function for RSA's DESX algorithm using a 24-byte key and an optional 8-byte initialization vector. This function returns a string, for an equivalent function that decrypts to a binary object, see desx_decrypt_cbc().

Usage
desx_decrypt_cbc_to_string(binary, key, [init_vector])
Example
$str = desx_decrypt_cbc_to_string($data, $key);

Table 3.178. Arguments and Return Values for desx_decrypt_cbc_to_string()

Argument Type

Return Type

Description

Binary, String 7 Binary, [String | Binary]

String

Decrypts data to a string using the Cipher Block Chaining function for RSA's DESX algorithm using a 24-byte key and an optional 8-byte initialization vector.


Table 3.179. Exceptions thrown by desx_decrypt_cbc_to_string()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

DESX-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.16. rc2_encrypt_cbc()

Synopsis

Encrypts data using the Cipher Block Chaining function for RSA's RC2(tm) algorithm using a variable-length key and an optional 8-byte initialization vector. Returns a binary object of the encrypted data.

Usage
rc2_encrypt_cbc(data, key, [init_vector])
Example
$bin = rc2_encrypt_cbc($data, $key);

Table 3.180. Arguments and Return Values for rc2_encrypt_cbc()

Argument Type

Return Type

Description

String | Binary, String | Binary, [String | Binary]

Binary

Encrypts data using the Cipher Block Chaining function for RSA's RC2(tm) algorithm using a variable-length key and an optional 8-byte initialization vector.


Table 3.181. Exceptions thrown by rc2_encrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

RC2-ENCRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.17. rc2_decrypt_cbc()

Synopsis

Decrypts data using the Cipher Block Chaining function for RSA's RC2(tm) algorithm using a variable-length key and an optional 8-byte initialization vector. This function returns a binary object, for an equivalent function that decrypts to a string, see rc2_decrypt_cbc_to_string().

Usage
rc2_decrypt_cbc(encrypted_data, key, [init_vector])
Example
$bin = rc2_decrypt_cbc($data, $key);

Table 3.182. Arguments and Return Values for rc2_decrypt_cbc()

Argument Type

Return Type

Description

Binary, String | Binary, [String | Binary]

Binary

Decrypts data using the Cipher Block Chaining function for RSA's RC2(tm) algorithm using a variable-length key and an optional 8-byte initialization vector.


Table 3.183. Exceptions thrown by rc2_decrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

RC2-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.18. rc2_decrypt_cbc_to_string()

Synopsis

Decrypts data to a string using the Cipher Block Chaining function for RSA's RC2(tm) algorithm using a variable-length key and an optional 8-byte initialization vector. This function returns a string, for an equivalent function that decrypts to a binary object, see rc2_decrypt_cbc().

Usage
rc2_decrypt_cbc_to_string(encrypted_data, key, [init_vector])
Example
$str = rc2_decrypt_cbc_to_string($data, $key);

Table 3.184. Arguments and Return Values for rc2_decrypt_cbc_to_string()

Argument Type

Return Type

Description

Binary, String | Binary, [String | Binary]

String

Decrypts data to a string using the Cipher Block Chaining function for RSA's RC2(tm) algorithm using a variable-length key and an optional 8-byte initialization vector.


Table 3.185. Exceptions thrown by rc2_decrypt_cbc_to_string()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

RC2-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.19. cast5_encrypt_cbc()

Synopsis

Encrypts data using the Cipher Block Chaining function for the CAST5 algorithm using a variable-length key and an optional 8-byte initialization vector. Returns a binary object of the encrypted data.

Usage
cast5_encrypt_cbc(data, key, [init_vector])
Example
$bin = cast5_encrypt_cbc($data, $key);

Table 3.186. Arguments and Return Values for cast5_encrypt_cbc()

Argument Type

Return Type

Description

String | Binary, String | Binary, [String | Binary]

Binary

Encrypts data using the Cipher Block Chaining function for the CAST5 algorithm using a variable-length key and an optional 8-byte initialization vector.


Table 3.187. Exceptions thrown by cast5_encrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

CAST5-ENCRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.20. cast5_decrypt_cbc()

Synopsis

Decrypts data using the Cipher Block Chaining function for the CAST5 algorithm using a variable-length key and an optional 8-byte initialization vector. This function returns a binary object, for an equivalent function that decrypts to a string, see cast5_decrypt_cbc_to_string().

Usage
cast5_decrypt_cbc(encrypted_data, key, [init_vector])
Example
$bin = cast5_decrypt_cbc($data, $key);

Table 3.188. Arguments and Return Values for cast5_decrypt_cbc()

Argument Type

Return Type

Description

Binary, Key, [init_vector]

Binary

Decrypts data using the Cipher Block Chaining function for the CAST5 algorithm using a variable-length key and an optional 8-byte initialization vector.


Table 3.189. Exceptions thrown by cast5_decrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

CAST5-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.21. cast5_decrypt_cbc_to_string()

Synopsis

Decrypts data to a string using the Cipher Block Chaining function for the CAST5 algorithm using a variable-length key and an optional 8-byte initialization vector. This function returns a string, for an equivalent function that decrypts to a binary object, see cast5_decrypt_cbc().

Usage
cast5_decrypt_cbc_to_string(binary, key, [init_vector])
Example
$str = cast5_decrypt_cbc_to_string($data, $key);

Table 3.190. Arguments and Return Values for cast5_decrypt_cbc_to_string()

Argument Type

Return Type

Description

Binary, Key, [init_vector]

String

Decrypts data to a string using the Cipher Block Chaining function for the CAST5 algorithm using a variable-length key and an optional 8-byte initialization vector.


Table 3.191. Exceptions thrown by cast5_decrypt_cbc_to_string()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

CAST5-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.22. rc4_encrypt()

Synopsis

Encrypts data using the Alleged RC4 cipher algorithm, which should be compatible with RSA's RC4(tm) algorithm using a variable-length key and an optional 8-byte initialization vector. Returns a binary object of the encrypted data.

Usage
rc4_encrypt(data, key, [init_vector])
Example
$bin = rc4_encrypt($data, $key);

Table 3.192. Arguments and Return Values for rc4_encrypt()

Argument Type

Return Type

Description

String | Binary, String | Binary, [String | Binary, ]

Binary

Encrypts data using the Alleged RC4 cipher algorithm, which should be compatible with RSA's RC4(tm) algorithm using a variable-length key and an optional 8-byte initialization vector.


Table 3.193. Exceptions thrown by rc4_encrypt()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

RC4-ENCRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.23. rc4_decrypt()

Synopsis

Decrypts data using the Alleged RC4 cipher algorithm, which should be compatible with RSA's RC4(tm) algorithm using a variable-length key and an optional 8-byte initialization vector. This function returns a binary object, for an equivalent function that decrypts to a string, see rc4_decrypt_to_string().

Usage
rc4_decrypt(binary, key, [init_vector])
Example
$bin = rc4_decrypt($data, $key);

Table 3.194. Arguments and Return Values for rc4_decrypt()

Argument Type

Return Type

Description

Binary, Key, [init_vector]

Binary

Decrypts data using the Alleged RC4 cipher algorithm, which should be compatible with RSA's RC4(tm) algorithm using a variable-length key and an optional 8-byte initialization vector.


Table 3.195. Exceptions thrown by rc4_decrypt()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

RC4-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.24. rc4_decrypt_to_string()

Synopsis

Decrypts data to a string using the Alleged RC4 cipher algorithm, which should be compatible with RSA's RC4(tm) algorithm using a variable-length key and an optional 8-byte initialization vector. This function returns a string, for an equivalent function that decrypts to a binary object, see rc4_decrypt().

Usage
rc4_decrypt_to_string(binary, key, [init_vector])
Example
$str = rc4_decrypt_to_string($data, $key);

Table 3.196. Arguments and Return Values for rc4_decrypt_to_string()

Argument Type

Return Type

Description

Binary, Key, [init_vector]

String

Decrypts data to a string using the Alleged RC4 cipher algorithm, which should be compatible with RSA's RC4(tm) algorithm using a variable-length key and an optional 8-byte initialization vector.


Table 3.197. Exceptions thrown by rc4_decrypt_to_string()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

RC4-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)


3.8.25. rc5_encrypt_cbc()

Synopsis

Encrypts data using the Cipher Block Chaining function for RSA's RC5(tm) algorithm using a variable-length key and an optional 8-byte initialization vector. Returns a binary object of the encrypted data. The availability of this function depends on the availability of the RC5 algorithm in the openssl library used to compile the Qore library; for maximum portability check the constant HAVE_RC5 before running this function. See Library Option Constants for a list of all option constants.

Usage
rc5_encrypt_cbc(data, key, [init_vector])
Example
$bin = rc5_encrypt_cbc($data, $key);

Table 3.198. Arguments and Return Values for rc5_encrypt_cbc()

Argument Type

Return Type

Description

String | Binary, String | Binary, [String | Binary]

Binary

Encrypts data using the Cipher Block Chaining function for RSA's RC5(tm) algorithm using a variable-length key and an optional 8-byte initialization vector.


Table 3.199. Exceptions thrown by rc5_encrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

RC5-ENCRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)

MISSING-FEATURE-ERROR

This exception is thrown when the function is not available; for maximum portability, check the constant HAVE_RC5 before calling this function.


3.8.26. rc5_decrypt_cbc()

Synopsis

Decrypts data using the Cipher Block Chaining function for RSA's RC5(tm) algorithm using a variable-length key and an optional 8-byte initialization vector. This function returns a binary object, for an equivalent function that decrypts to a string, see rc5_decrypt_cbc_to_string(). The availability of this function depends on the availability of the RC5 algorithm in the openssl library used to compile the Qore library; for maximum portability check the constant HAVE_RC5 before running this function. See Library Option Constants for a list of all option constants.

Usage
rc5_decrypt_cbc(binary, key, [init_vector])
Example
$bin = rc5_decrypt_cbc($data, $key);

Table 3.200. Arguments and Return Values for rc5_decrypt_cbc()

Argument Type

Return Type

Description

Binary, Key, [init_vector]

Binary

Decrypts data using the Cipher Block Chaining function for RSA's RC5(tm) algorithm using a variable-length key and an optional 8-byte initialization vector.


Table 3.201. Exceptions thrown by rc5_decrypt_cbc()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

RC5-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)

MISSING-FEATURE-ERROR

This exception is thrown when the function is not available; for maximum portability, check the constant HAVE_RC5 before calling this function.


3.8.27. rc5_decrypt_cbc_to_string()

Synopsis

Decrypts data to a string using the Cipher Block Chaining function for RSA's RC5(tm) algorithm using a variable-length key and an optional 8-byte initialization vector. This function returns a string, for an equivalent function that decrypts to a binary object, see rc5_decrypt_cbc(). The availability of this function depends on the availability of the RC5 algorithm in the openssl library used to compile the Qore library; for maximum portability check the constant HAVE_RC5 before running this function. See Library Option Constants for a list of all option constants.

Usage
rc5_decrypt_cbc_to_string(encrypted_data, key, [init_vector])
Example
$str = rc5_decrypt_cbc_to_string($data, $key);

Table 3.202. Arguments and Return Values for rc5_decrypt_cbc_to_string()

Argument Type

Return Type

Description

Binary, Key, [init_vector]

String

Decrypts data to a string using the Cipher Block Chaining function for RSA's RC5(tm) algorithm using a variable-length key and an optional 8-byte initialization vector.


Table 3.203. Exceptions thrown by rc5_decrypt_cbc_to_string()

err

desc

PARAMETER-ERROR

missing data (string or binary) parameter to function, invalid data type (expecing string or binary)

RC5-DECRYPT-PARAM-ERROR

missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present)

MISSING-FEATURE-ERROR

This exception is thrown when the function is not available; for maximum portability, check the constant HAVE_RC5 before calling this function.