class CI_Encryption
-
initialize($params)
-
Parameters: - $params (array) – Configuration parameters
Returns: CI_Encryption instance (method chaining)
Return type: CI_Encryption
Initializes (configures) the library to use a different driver, cipher, mode or key.
Example:
$this->encryption->initialize( array('mode' => 'ctr') );
Please refer to the Configuring the library section for detailed info.
-
encrypt($data[, $params = NULL])
-
Parameters: - $data (string) – Data to encrypt
- $params (array) – Optional parameters
Returns: Encrypted data or FALSE on failure
Return type: string
Encrypts the input data and returns its ciphertext.
Example:
$ciphertext = $this->encryption->encrypt('My secret message');
Please refer to the Using custom parameters section for information on the optional parameters.
-
decrypt($data[, $params = NULL])
-
Parameters: - $data (string) – Data to decrypt
- $params (array) – Optional parameters
Returns: Decrypted data or FALSE on failure
Return type: string
Decrypts the input data and returns it in plain-text.
Example:
echo $this->encryption->decrypt($ciphertext);
Please refer to the Using custom parameters secrion for information on the optional parameters.
-
create_key($length)
-
Parameters: - $length (int) – Output length
Returns: A pseudo-random cryptographic key with the specified length, or FALSE on failure
Return type: string
Creates a cryptographic key by fetching random data from the operating system’s sources (i.e. /dev/urandom).
-
hkdf($key[, $digest = 'sha512'[, $salt = NULL[, $length = NULL[, $info = '']]]])
-
Parameters: - $key (string) – Input key material
- $digest (string) – A SHA-2 family digest algorithm
- $salt (string) – Optional salt
- $length (int) – Optional output length
- $info (string) – Optional context/application-specific info
Returns: A pseudo-random key or FALSE on failure
Return type: string
Derives a key from another, presumably weaker key.
This method is used internally to derive an encryption and HMAC key from your configured encryption_key.
It is publicly available due to its otherwise general purpose. It is described in RFC 5869.
However, as opposed to the description in RFC 5869, this implementation doesn’t support SHA1.
Example:
$hmac_key = $this->encryption->hkdf( $key, 'sha512', NULL, NULL, 'authentication' ); // $hmac_key is a pseudo-random key with a length of 64 bytes
Please login to continue.