Modules

abstract Kohana_Encrypt

This class is a transparent base class for Encrypt and should not be accessed directly.

Kohana Encrypt provides a common interface to a variety of cryptography engines, supports multiple instances of cryptography engines through a grouped singleton pattern.

package
Kohana
category
Security
author
Tinsh
copyright
© 2018 Kohana Group
license
https://kohana.top/license

Class declared in SYSPATH/classes/Kohana/Encrypt.php on line 14.

Constants

  • None

Properties

Properties

public static string $default

Default instance name.

string(7) "default"

public static array $instances

Encrypt class instances.

array(0) 

Methods

abstract public decode( string $data ) (defined in Kohana_Encrypt)

Decrypts an encoded string back to its original value.

$data = $encrypt->decode($data);

Parameters

  • string $data required - Encoded string to be decrypted.

Return Values

  • false - If decryption fails.
  • string

Source Code

abstract public function decode($data);

abstract public encode( string $data ) (defined in Kohana_Encrypt)

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.

Parameters

  • string $data required - Data to be encrypted.

Return Values

  • string

Source Code

abstract public function encode($data);

public static instance( [ string $name = NULL , array $config = NULL ] ) (defined in Kohana_Encrypt)

Creates a singleton instance of Encrypt. An encryption key must be provided in your "encrypt" configuration file.

$encrypt = Encrypt::instance();

Parameters

  • string $name = NULL - Configuration group name.
  • array $config = NULL - Configuration parameters.

Return Values

  • Encrypt

Source Code

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];
}