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 binary sub get_key(int $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 File $f(); # File::open2() will throw an exception if /dev/random cannot be opened for reading $f.open2("/dev/random"); return $f.readBinary($size); }
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.
binaryblowfish_encrypt_cbc(data$data, data$key, data$iv = defaultIV)
$bin = blowfish_encrypt_cbc("hello there", $key);Table 3.180. Exceptions thrown by blowfish_encrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
binaryblowfish_decrypt_cbc(binary$encrypted_data, data$key, data$iv = defaultIV)
$bin = blowfish_decrypt_cbc($encrypted_binary_data, $key);
Table 3.182. Exceptions thrown by blowfish_decrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
stringblowfish_decrypt_cbc_to_string(binary$encrypted_data, data$key, data$iv = defaultIV)
$str = blowfish_decrypt_cbc_to_string($bin, $key);
Table 3.184. Exceptions thrown by blowfish_decrypt_cbc_to_string()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
Table 3.185. Arguments and Return Values for des_encrypt_cbc()
Argument Type | Return Type | Description |
|---|---|---|
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.186. Exceptions thrown by des_encrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
binarydes_decrypt_cbc(binary$encrypted_data, data$key, data$iv = defaultIV)
Table 3.188. Exceptions thrown by des_decrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
stringdes_decrypt_cbc_to_string(binary$encrypted_data, data$key, data$iv = defaultIV)
Table 3.190. Exceptions thrown by des_decrypt_cbc_to_string()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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.
binarydes_ede_encrypt_cbc(data$data, data$key, data$iv = defaultIV)
$bin = des_ede_encrypt_cbc($text, $key);
Table 3.191. Arguments and Return Values for des_ede_encrypt_cbc()
Argument Type | Return Type | Description |
|---|---|---|
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.192. Exceptions thrown by des_ede_encrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
binarydes_ede_decrypt_cbc(binary$encrypted_data, data$key, data$iv = defaultIV)
$bin = des_ede_decrypt_cbc($data, $key);
Table 3.193. Arguments and Return Values for des_ede_decrypt_cbc()
Argument Type | Return Type | Description |
|---|---|---|
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.194. Exceptions thrown by des_ede_decrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
stringdes_ede_decrypt_cbc_to_string(binary$encrypted_data, data$key, data$iv = defaultIV)
$str = des_ede_decrypt_cbc_to_string($data, $key);
Table 3.195. Arguments and Return Values for des_ede_decrypt_cbc_to_string()
Argument Type | Return Type | Description |
|---|---|---|
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.196. Exceptions thrown by des_ede_decrypt_cbc_to_string()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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.
binarydes_ede3_encrypt_cbc(data$data, data$key, data$iv = defaultIV)
$bin = des_ede3_encrypt_cbc($data, $key);
Table 3.197. Arguments and Return Values for des_ede3_encrypt_cbc()
Argument Type | Return Type | Description |
|---|---|---|
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.198. Exceptions thrown by des_ede3_encrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
binarydes_ede3_decrypt_cbc(binary$encrypted_data, data$key, data$iv = defaultIV)
$bin = des_ede3_decrypt_cbc($data, $key);
Table 3.200. Exceptions thrown by des_ede3_decrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
stringdes_ede3_decrypt_cbc_to_string(binary$encrypted_data, data$key, data$iv = defaultIV)
$str = des_ede3_decrypt_cbc_to_string($data, $key);
Table 3.201. Arguments and Return Values for des_ede3_decrypt_cbc_to_string()
Argument Type | Return Type | Description |
|---|---|---|
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.202. Exceptions thrown by des_ede3_decrypt_cbc_to_string()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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.
binarydesx_encrypt_cbc(data$data, data$key, data$iv = defaultIV)
$bin = desx_encrypt_cbc($data, $key);
Table 3.204. Exceptions thrown by desx_encrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
binarydesx_decrypt_cbc(binary$encrypted_data, data$key, data$iv = defaultIV)
my binary $bin = desx_decrypt_cbc($data, $key);Table 3.206. Exceptions thrown by desx_decrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
stringdesx_decrypt_cbc_to_string(binary$encrypted_data, data$key, data$iv = defaultIV)
$str = desx_decrypt_cbc_to_string($data, $key);
Table 3.208. Exceptions thrown by desx_decrypt_cbc_to_string()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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.
binaryrc2_encrypt_cbc(data$data, data$key, data$iv = defaultIV)
$bin = rc2_encrypt_cbc($data, $key);
Table 3.210. Exceptions thrown by rc2_encrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
binaryrc2_decrypt_cbc(binary$encrypted_data, data$key, data$iv = defaultIV)
$bin = rc2_decrypt_cbc($data, $key);
Table 3.212. Exceptions thrown by rc2_decrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
stringrc2_decrypt_cbc_to_string(binary$encrypted_data, data$key, data$iv = defaultIV)
$str = rc2_decrypt_cbc_to_string($data, $key);
Table 3.214. Exceptions thrown by rc2_decrypt_cbc_to_string()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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.
binarycast5_encrypt_cbc(data$data, data$key, data$iv = defaultIV)
$bin = cast5_encrypt_cbc($data, $key);
Table 3.216. Exceptions thrown by cast5_encrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
binarycast5_decrypt_cbc(binary$encrypted_data, data$key, data$iv = defaultIV)
$bin = cast5_decrypt_cbc($data, $key);
Table 3.218. Exceptions thrown by cast5_decrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
stringcast5_decrypt_cbc_to_string(binary$encrypted_data, data$key, data$iv = defaultIV)
$str = cast5_decrypt_cbc_to_string($data, $key);
Table 3.220. Exceptions thrown by cast5_decrypt_cbc_to_string()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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.
binaryrc4_encrypt(data$data, data$key, data$iv = defaultIV)
$bin = rc4_encrypt($data, $key);
Table 3.222. Exceptions thrown by rc4_encrypt()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
binaryrc4_decrypt(binary$encrypted_data, data$key, data$iv = defaultIV)
$bin = rc4_decrypt($data, $key);
Table 3.224. Exceptions thrown by rc4_decrypt()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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().
stringrc4_decrypt_to_string(binary$encrypted_data, data$key, data$iv = defaultIV)
$str = rc4_decrypt_to_string($data, $key);
Table 3.226. Exceptions thrown by rc4_decrypt_to_string()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
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.
binaryrc5_encrypt_cbc(data$data, data$key, data$iv = defaultIV)
$bin = rc5_encrypt_cbc($data, $key);
Table 3.228. Exceptions thrown by rc5_encrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
| This exception is thrown when the function is not available; for maximum portability, check the constant |
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().
binaryrc5_decrypt_cbc(binary$encrypted_data, data$key, data$iv = defaultIV)
$bin = rc5_decrypt_cbc($data, $key);
Table 3.230. Exceptions thrown by rc5_decrypt_cbc()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
| This exception is thrown when the function is not available; for maximum portability, check the constant |
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().
stringrc5_decrypt_cbc_to_string(binary$encrypted_data, data$key, data$iv = defaultIV)
$str = rc5_decrypt_cbc_to_string($data, $key);
Table 3.232. Exceptions thrown by rc5_decrypt_cbc_to_string()
err | desc |
|---|---|
| missing data (string or binary) parameter to function, invalid data type (expecing string or binary) |
| missing or invalid key parameter (ex: invalid size) or invalid initialization vector (less than 8 bytes, only raised if initialization vector present) |
| This exception is thrown when the function is not available; for maximum portability, check the constant |
There are no comments yet