Kohana Encrypt provides a common interface to a variety of cryptography engines, supports multiple instances of cryptography engines through a grouped singleton pattern.
Class declared in SYSPATH/classes/Encrypt.php on line 3.
string
$defaultlink to thisDefault instance name.
string(7) "default"
array
$instanceslink to thisEncrypt class instances.
array(0)
Decrypts an encoded string back to its original value.
$data
=
$encrypt
->decode(
$data
);
string
$data
required - Encoded string to be decrypted. false
- If decryption fails.string
abstract
public
function
decode(
$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 encrypted. string
abstract
public
function
encode(
$data
);
Creates a singleton instance of Encrypt. An encryption key must be provided in your "encrypt" configuration file.
$encrypt
= Encrypt::instance();
string
$name
= NULL - Configuration group name. array
$config
= NULL - Configuration parameters. Encrypt
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
[
'driver'
])) {
throw
new
Kohana_Exception(
'No encryption driver is defined in the encryption configuration group: :group'
, [
':group'
=>
$name
]);
}
// Set the driver class name
$driver
=
'Encrypt_'
. ucfirst(
$config
[
'driver'
]);
// Create a new instance
Encrypt::
$instances
[
$name
] =
new
$driver
(
$name
,
$config
);
}
return
Encrypt::
$instances
[
$name
];
}