Class declared in MODPATH/encrypt/classes/Encrypt.php on line 3.
engine
$_engineEncryption engine
NULL
string
$defaultdefault instance name
string(7) "default"
array
$instancesEncrypt class instances
array(0)
Creates a new mcrypt wrapper.
string
$key_config
required - Encryption key or config arraystring
$mode
= NULL - Encryption modestring
$cipher
= NULL - Encryption cipherpublic function __construct($key_config, $mode = NULL, $cipher = NULL)
{
if (is_string($key_config))
{
$this->_engine = new Encrypt_Engine_Mcrypt($key_config, $mode, $cipher);
}
else
{
if ( ! isset($key_config['type']))
{
$key_config['type'] = 'mcrypt';
}
// Set the engine class name
$engine_name = 'Encrypt_Engine_'.ucfirst($key_config['type']);
// Create the engine class
$this->_engine = new $engine_name($key_config);
}
}
Decrypts an encoded string back to its original value.
$data = $encrypt->decode($data);
string
$data
required - Encoded string to be decryptedFALSE
- If decryption failsstring
public function decode($data)
{
return $this->_engine->decrypt($data);
}
Encrypts a string and returns an encrypted string that can be decoded.
$data = $encrypt->encode($data);
The encrypted binary data is encoded using base64 to convert it to a string. This string can be stored in a database, displayed, and passed using most other means without corruption.
string
$data
required - Data to be encryptedstring
public function encode($data)
{
// Get an initialization vector
$iv = $this->_create_iv();
return $this->_engine->encrypt($data, $iv);
}
Returns a singleton instance of Encrypt. An encryption key must be provided in your "encrypt" configuration file.
$encrypt = Encrypt::instance();
string
$name
= NULL - Configuration group nameunknown
$config
= NULLEncrypt
public static function instance($name = NULL, array $config = NULL)
{
if ($name === NULL)
{
// Use the default instance name
$name = Encrypt::$default;
}
if ( ! isset(Encrypt::$instances[$name]))
{
if ($config === NULL)
{
// Load the configuration data
$config = Kohana::$config->load('encrypt')->$name;
}
if ( ! isset($config['key']))
{
// No default encryption key is provided!
throw new Kohana_Exception('No encryption key is defined in the encryption configuration group: :group',
[':group' => $name]);
}
// Create a new instance
Encrypt::$instances[$name] = new Encrypt($config);
}
return Encrypt::$instances[$name];
}
Proxy for the mcrypt_create_iv function - to allow mocking and testing against KAT vectors
string
- The initialization vector or FALSE on errorprotected function _create_iv()
{
return $this->_engine->create_iv();
}