Fuel Documentation

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 is very important that you configure a truly random salt for your application, even if you don't use the Crypt class directly.

Configuration

The Crypt class is configured through the app/config/crypt.php configuration file. It is already populated with default configuration values.

The following configuration settings can be defined:

Param Type Default Description
salt string
'sup3rs3Cr3tk3y564'
Random salt value used in the encryption routines for extra entropy. Make sure you set this to something unique and random!
use_mcrypt boolean
true
Optional: Indicates if you want to use PHP's Mcrypt library if available. It is a lot faster, but might cause your data not to be portable anymore (all target platforms need to have Mcrypt installed as well).
mcrypt_cipher integer
MCRYPT_RIJNDAEL_256
Optional: http://www.php.net/manual/en/mcrypt.ciphers.php for available ciphers.
mcrypt_mode integer
MCRYPT_MODE_CBC
Optional: http://www.php.net/manual/en/mcrypt.constants.php for available cipher modes.

encode($value, $salt = false)

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

Static No
Parameters
Param Default Description
$value Required String value to encode.
$salt
false
Optional custom salt value to be used to add more entropy to the value to encode.
Returns string
Example
// encode a variable with a custom salt
$value = Crypt::encode($value, 'R@nd0mS@1t');

decode($value, $salt = false)

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

Static No
Parameters
Param Default Description
$value Required String value to decode.
$salt
false
Optional custom salt value used when the $value was encoded.
Returns mixed - String value with the decoded value, or false if the value could not be decoded.
Example
// decode a variable with a custom salt
$value = Crypt::decode($value, 'R@nd0mS@1t');
Throws Exception in case the $value passed was encoding using the Mcrypt library, but Mcrypt is not available to decode it.