Crypt Class

The Crypt class allows encrypt or decrypt a string. The Crypt class is also used internally by for example the Fuel Sessions class.

It uses the encryption and hashing methods provided by PHPSecLib, so it's not dependent on external modules being available, such as mcrypt.

Usage

Using crypt can be done in 2 ways: through static usage of the Crypt class and through crypt objects returned by the Crypt::forge() or Crypt::instance() methods. This section covers static usage which will always work with the default instance using the configuration specified in the configuration.

Using crypt objects, Crypt::instance() and Crypt::forge() is explained in the advanced section.

encode($value, $key = false)

The encode method encrypts a string value, optionally with a custom encryption key.

Static No
Parameters
Param Default Description
$value Required String value to encode.
$key
false
Optional custom key value to be used to encode the value passed. If false, the config value 'crypto_key' is used.
Returns string
Example
// encode a variable with a custom key
$value = Crypt::encode($value, 'R@nd0mK~Y');

decode($value, $key = false)

The decode method decrypts a string value, optionally with a custom key.

Static No
Parameters
Param Default Description
$value Required String value to decode.
$key
false
Optional custom key value to be used to decode the value passed. If false, the config value 'crypto_key' is used.
Returns mixed - String value with the decoded value, or false if the value could not be decoded.
Example
// decode a variable with a custom key
$value = Crypt::decode($value, 'R@nd0mK~Y');